【发布时间】:2013-10-10 08:18:50
【问题描述】:
在我的 Ember 应用程序中,我有一个 ArrayController,我在其中创建了一个方法:
App.SwatchesController = Ember.ArrayController.extend({
push: function (color) {
var model = this.get('model');
/* do a few things */
this.set('model', model);
}
});
当我尝试从ApplicationCotroller 中的操作调用此方法时,我得到一个TypeError:
App.ApplicationController = Ember.Controller.extend({
actions: {
parse: function () {
App.SwatchesController.push('#fff'); // TypeError: Object function (){/* long body here */} has no method 'push'
}
}
});
我应该在 Ember 中使用控制器方法吗?不幸的是,官方文档仅提供了有限的控制器示例。
我可能可以将模型定义为App.Swatches 并直接从ApplicationController 管理它,但我相信我不应该这样做,因为SwatchesController 的用途是。
【问题讨论】:
标签: javascript model-view-controller ember.js