我正在尝试使用 Ember 在 ContainerView 中动态创建子视图。
问题是那些子视图需要数据绑定到来自容器视图的属性值。
这是一些代码,大致显示了我在做什么:
ReferenceCat.EditorView = Ember.ContainerView.extend({
init: function(){
this._super();
if(this.get('model.type') != undefined){
this.modelTypeChanges();
}
},
modelTypeChanges : function(){
// 1st step: Remove all children of my view
this.removeAllChildren();
var model = this.get('model');
// 2nd step is to run through all of the type information
// generating the views that we need to actually
// fill in this reference
var tI = model.get('typeInfo');
var self = this;
tI.forEach(function(field){
// Now we have a field
switch(field.type){
case "string":
// add new child view here with data binding to data.<field.name>
break;
}
});
}
});
这个类是这样引用的:
{{view ReferenceCat.EditorView
modelBinding=model}}