マップを表すコンポーネントがあり、コントローラーでアクションを実行した後、コンポーネントのメソッドを呼び出してマップを中央に配置したいと考えています。コードは次のようになります
App.PlacesController = Ember.Controller.extend({
actions : {
centerMap : function () {
// how to call from here to GoogleMapComponent.centerMap ??
}
}
});
App.GoogleMapComponent = Ember.Component.extend({
centerMap : function () {
}
});
テンプレート
{{google-map}}
<button {{action "centerMap"}}>Center Map</button>
回避策を見つけましたが、これが Ember のやり方だとは思いません。
{{google-map viewName="mapView"}}
<button class="center-map">Center Map</button>
App.PlacesView = Ember.View.extend({
didInsertElement : function () {
this.$(".center-map").click(this.clickCenterMap.bind(this));
},
clickCenterMap : function () {
this.get("mapView").centerMap();
}
});