javascript - 在同一路由内调用操作方法

标签 javascript ember.js

我正在尝试在同一 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')
});

工作箱:http://emberjs.jsbin.com/rununifupono/7/edit

关于javascript - 在同一路由内调用操作方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25571282/

相关文章:

javascript - Ember js : if equals issue with params

javascript - 更新侧边栏 View 内容的 Ember.js 最佳实践是什么?

javascript - 如果我重新启动应用程序池,客户端浏览器是否会引用我更新的 javascript 或 css 文件?

javascript - Ember.RSVP.hash 重新加载内部 promise

ember.js - ember js如何删除我的网址中的哈希标签

javascript - 单击按钮时未定义(文本框值)

javascript - Safari iOS 6 - ajax 请求 blob 图像

javascript - Meteor 中的复合集合

javascript - 将 div 更改为绝对位置时,它会跳转到原始位置

javascript - Telegram 框架。如何使用 telegram.forwardMessage(); 将消息转发到给定的群组、聊天或 channel ?