3
我在学习ember.js,我还没有构建任何东西。Ember.js - 如何绑定嵌套集合中的控制器?
我将我的数据存储在模型对象中,并使用控制器充当视图和模型之间的粘合剂。控制器将内容设置为模型的实例,并且该视图具有对控制器中的内容(并且因此与代理的模型)的绑定。像这样:
// js
App.MyModel = Ember.Object.extend({foo:''});
App.myController = Ember.Object.create({
content: App.MyModel.create()
});
// html
{{view Ember.TextInput valueBinding="App.myController"}}
到目前为止这么好。但我不知道怎么这种模式适用于嵌套集合:
//js
App.ChildController = Ember.ArrayController.extend();
App.NestedModel = Ember.Object.extend({
init: function() {
this._super();
this.set('children', []);
// Here: I can't give a global name for the content binding, and I don't know how to give a relative one
this.set('childController', App.ChildController.create({contentBinding: 'children');
}
});
App.myController = Ember.ArrayController.create({
content:[],
newChild: function() {
this.pushObject(App.NestedModel.create());
}
});
// html
{{#collection contentBinding="App.myController"}}
{{#collection contentBinding="content.childController"}} <!-- nope -->
{{content.childField}}
{{/collection}}
{{/collection}}
这里的东西,你可以拨弄:http://jsfiddle.net/DwheG/
什么我问的是:
- 我是连建模正确的东西?
- 如何绑定子控制器的内容?我必须使用字符串吗?传递对象(
this
)没有为我工作。 Ember的路径解析算法在任何地方都有记录吗? - 如何将嵌套收集帮助程序绑定到嵌套控制器?
哈哈stackoverflow删除了“你好,”在我的问题开始...和hvgotcodes删除了“世界”:) – peets 2012-07-13 17:14:18