[英]Ember.js - Propagate event up the controller/router chain
在Ember.js中,未在控制器中處理的事件將路由器鏈向上傳播到應用程序路由(有關詳細信息,請參閱http://emberjs.com/guides/views/handling-events/ )。
有沒有辦法在控制器中定義一個事件處理程序,允許事件繼續傳播到路由器?
App.SampleController = Ember.ObjectController.extend({
myEvent: function(obj) {
this.set('aVariable', true);
}
});
App.ApplicationRoute = Ember.Route.extend({
events: {
myEvent: function(obj) {
this.transitionTo('something');
}
}
});
是否有一種方法可以讓CarsController中的myEvent處理程序設置其內部狀態變量,同時也可以將鏈上的事件踢到應用程序路徑? 我知道這件事:
App.__container__.lookup('router:main').send('myEvent', obj);
但它使用了Ember內部。 我希望有更標准的方法來做到這一點。
實現這一目標的一種方法是:
App.SampleController = Ember.ObjectController.extend({
needs: 'application',
myEvent: function(obj) {
this.set('aVariable', true);
this.get('controllers.application').send('myEvent');
}
});
工作演示 。
希望能幫助到你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.