本文介绍了Ember CollectionView具有不同模板的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于我有以下代码:

  Ember.App.View = Ember.View.extend({
templateName:templateA
});
Ember.App.View = Ember.View.extend({
templateName:templateB
});
Ember.App.ViewC = Ember.CollectionView.extend({
itemViewClass:Ember.View,
contentBinding:SomeController
});

有没有办法添加不同模板的视图到CollectionView?

解决方案

另一个解决方案是使用,请参阅:

  App.ViewA = Ember.View.extend({
templateName:templateA
});
App.ViewB = Ember.View.extend({
templateName:templateB
});

App.ItemView = Ember.View.extend({
template:Ember.Handlebars.compile('{{dynamicView content}}')
});

App.CollectionView = Ember.CollectionView.extend({
itemViewClass:'App.ItemView'
});

App.controller = Ember.ArrayProxy.create({
content:[App.ViewA.create(),App.ViewB.create()]
});


Given that I have this code:

Ember.App.View = Ember.View.extend({
    templateName: "templateA"
});
Ember.App.View = Ember.View.extend({
    templateName: "templateB"
});
Ember.App.ViewC = Ember.CollectionView.extend({
    itemViewClass: "Ember.View",
    contentBinding: "SomeController"
});

Is there a way to add views with different templates to CollectionView?

解决方案

Another solution is to use ghempton/ember-layout, see http://jsfiddle.net/pangratz666/XhfYy/:

App.ViewA = Ember.View.extend({
    templateName: "templateA"
});
App.ViewB = Ember.View.extend({
    templateName: "templateB"
});

App.ItemView = Ember.View.extend({
    template: Ember.Handlebars.compile('{{dynamicView content}}')
});

App.CollectionView = Ember.CollectionView.extend({
    itemViewClass: 'App.ItemView'
});

App.controller = Ember.ArrayProxy.create({
    content: [App.ViewA.create(), App.ViewB.create()]
});​

这篇关于Ember CollectionView具有不同模板的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 10:10