我有一个代表地图的组件,在我的控制器中执行操作之后,我想调用组件上的方法来使地图居中.代码看起来像这样
App.PlacesController = Ember.Controller.extend({
actions : {
centerMap : function () {
// how to call from here to GoogleMapComponent.centerMap ??
}
}
});
App.GoogleMapComponent = Ember.Component.extend({
centerMap : function () {
}
});
Run Code Online (Sandbox Code Playgroud)
模板
{{google-map}}
<button {{action "centerMap"}}>Center Map</button>
Run Code Online (Sandbox Code Playgroud)
我找到了一个解决方法,但我认为这不是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();
}
});
Run Code Online (Sandbox Code Playgroud) 我在ember.js上进行实时搜索.这是代码
App.Router.map ->
@resource "index", {path : "/"}
@resource "index", {path : "/:query"}
App.Torrents =
findByQuery : (query) ->
url = "/api/find/#{query}"
$.getJSON(url)
App.IndexRoute = Ember.Route.extend
model : (params) ->
App.Torrents.findByQuery(params.query)
App.IndexController = Ember.ArrayController.extend
onChangeQuery : _.debounce(->
query = @get("query")
@transitionToRoute("index", {query : query})
, 500).observes("query")
Run Code Online (Sandbox Code Playgroud)
我有一个绑定到输入的查询属性.当输入更改我想转换到传递新查询参数的路由时,但是没有调用IndexRoute.model方法.