新创建的记录控制器的触发动作

时间:2014-06-06 13:04:22

标签: ember.js

我有两套控制器/型号;我们称他们为FoodDrink

让我们说我的控制器看起来像这样:

App.FoodController = Ember.Controller.extend({
  actions: {
    createDrink: function() {
      var drink = this.store.createRecord('drink');
      drink.save()
    }
  }
});

App.DrinkController = Ember.Controller.extend({
  actions: {
    fooBar: function() {
      console.log('Drink created from FoodController');
    }
  }
});

我想要做的是在fooBar使用DrinkController动作创建新的Drink记录后触发FoodController中声明的createDrink动作。任何想法如何做到这一点?

1 个答案:

答案 0 :(得分:0)

您可以使用需要然后抓住控制器,并使用发送。 http://emberjs.com/guides/controllers/dependencies-between-controllers/

App.FoodController = Ember.Controller.extend({
  needs:['drink'],
  actions: {
    createDrink: function() {
      var drink = this.store.createRecord('drink');
      drink.save();
      this.get('controllers.drink').send('fooBar');
    }
  }
});