控制器或路由如何向自己发送动作

时间:2015-01-18 22:59:12

标签: ember.js

鉴于以下代码,路线如何称之为doSomething动作?

export default Ember.Route.extend({
  setupController: function(controller, model) {
    // call the doSomething action
  },
  actions: {
    doSomething: function() { ... }
  }
}

1 个答案:

答案 0 :(得分:3)

您可以使用Transition / beforeModel / model挂钩传递的afterModel对象。

App.IndexRoute = Ember.Route.extend({
  actions: {
    doSomething() {
      console.log('doSomethingInvoked');
    }
  },
  beforeModel(transition) {
    transition.send('doSomething');
  },
  model(params, transition) {
    transition.send('doSomething');
  },
  afterModel(model, transition) {
    transition.send('doSomething');
  }
});

Working demo.