我需要在ItemController中调用一个函数/或者从ArrayController设置子ItemController的新属性。
为了更好的图片
App.ProductsController = Ember.ArrayController.extend({
needs: ["product"],
itemController: 'product',
contentChanged: function() { //no idea how to initiate this, hence I use observes
// How do I access the children controllers from here?
// I had tried below, but not working:
// this.get("content").forEach(function(item) {
// item.doSomething();
// });
}.observes('content')
});
App.ProductController = Ember.ObjectController.extend({
doSomething: function() {
//supposed to do something
}
});
我还没有找到任何办法。
答案 0 :(得分:1)
这应该是arrayController实例本身的forEach。 this.get("content")
此处返回未包含在itemController
this.forEach(function(item) {
item.doSomething();
});
答案 1 :(得分:0)
问题在于“观察”。在contentController中正确包装模型之前,“内容”会发生变化(在本例中为App.ProductController)。
因此,观察变化的正确方法是覆盖
//in App.ProductsController (aka Parent Controller)
arrayContentDidChange: function(startIdx, removeAmt, addAmt) {
this._super(startIdx, removeAmt, addAmt);
//then look for the children as such:
this.forEach(function(item){
item.doSomething();
});
}