我正在尝试在同一 route 调用“操作”方法。
当我做类似的事情时出现错误:
Nothing handled the action 'refreshFoo'. If you did handle the action, this error can be caused by returning true from an action handler in a controller, causing the action to bubble.
这是我的代码:
export default Ember.Route.extend({
setupController: function (controller, model) {
this._super(controller, model);
this.send('refreshFoo');
},
actions: {
refreshFoo: function () {
alert('refreshed!');
}
}
});
http://emberjs.jsbin.com/rununifupono/2/edit
知道出了什么问题吗?我是否正确使用了发送方法?
谢谢
最佳答案
该错误是因为在 setupController
内部,IndexRoute
未完全具体化,因此当您发送操作时,它只能由 ApplicationRoute
处理
为了使其按照您希望的方式工作,您需要将调用包装在 Ember.run.later
像这样
Ember.run.later(this, function(){
this.send('refreshFoo')
});
关于javascript - 在同一路由内调用操作方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25571282/