我有两套控制器/型号;我们称他们为Food
和Drink
。
让我们说我的控制器看起来像这样:
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
动作。任何想法如何做到这一点?
答案 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');
}
}
});