如何从ArrayController访问ItemController
How to access ItemController from ArrayController
我需要调用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
}
});
我没有找到任何方法来做这件事。
应该是arrayController实例本身上的forEach。这里的this.get("content")
返回未封装在itemController 中的模型数组
this.forEach(function(item) {
item.doSomething();
});
问题在于"观察"。在模型被正确包装在itemController(在本例中是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();
});
}
相关文章:
- 访问布局信息是否也会导致浏览器重排
- Javascript,访问一个主要对象模块模式中的每个对象
- 如何访问声音管理器2创建的声音对象
- 在Twitter上用ie9中的空白src访问iframe的contentWindow
- JavaScript Pub/Sub属性访问问题
- 从JavaScript访问struts操作中的属性
- 是否可以从父类访问子类的属性
- 如何访问fastOpt.js
- 访问JSON对象内部的数组元素
- 从模块内部访问Express装载路径
- 难以访问的JS环境中的语法错误
- 如何从对象的原型方法访问JavaScript对象属性
- 访问json数组中的对象
- 通过javascript/html访问twitter共享iframe
- Dojo:访问dijit.form.Select中单击的项目
- 为什么在这个网站上不能通过JS访问元素
- 从ng模板访问作用域
- 如何访问UIWebView'的子窗口上下文
- 使用Javascript获取Twitter访问令牌
- 访问jsrender模板中的全局javascript变量并更新它