У меня есть компонент, представляющий карту, и после действия в моем контроллере я хочу вызвать метод для компонента, чтобы центрировать карту. Код выглядит следующим образом:
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();
}
});