骨干木偶不同的复合意见 [英] Backbone Marionette different composite views
本文介绍了骨干木偶不同的复合意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能在木偶里面不同的项目意见的综合看法?例如:
Is it possible to have a composite view in marionette with DIFFERENT item views inside? For example:
var myCompositeView = Backbone.Marionette.CompositeView.extend({
template: Handlebars.compile(myTemplate),
itemView: myView, // I want different views, not just myView
initialize: function(){
this.collection = this.model.views;
},
appendHtml: function(collectionView, itemView){
collectionView.$('.container').append(itemView.el);
}
});
基本上,这取决于集合中的模式,我想创建一个一定的看法。
Basically, depending on the model in the collection, I want to create a certain view.
推荐答案
您可以用getItemView方法做到这一点:
You can accomplish this with the getItemView method:
var VTbody = Backbone.Marionette.CompositeView.extend({
template: "#emptyTemplate",
tagName:"tbody",
//itemView:VTr, /*No need to specify item View */
getItemView: function(item){
if(item.get("type")=="details") {
return VTrDetails
} else {
return VTr
}
}
});
下面项指集合中的模型。
希望这有助于。
Here item means the model in the collection. Hope this helps.
这篇关于骨干木偶不同的复合意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文