给定以下代码,路由如何调用它的doSomething操作?

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

最佳答案

您可以使用通过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.

关于ember.js - Controller 或路由如何向自身发送 Action ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28015800/

10-12 13:41