根据所选模板,我不想绑定到我想自己分配相应viewModel数据的文章。
我该怎么做?
<div data-bind="template: { name: getTemplate(), foreach: articles }"></div>
答案 0 :(得分:0)
而不是将foreach与articles属性绑定。 您可以使用返回正确视图模型的计算属性绑定foreach。
templateData = ko.computed(function(){
if(this.getTemplate() == 'articlesTemplate')
return this.articles;
if(this.getTemplate() == 'docTemplate')
return this.docs;
...
}, this)
我希望它有所帮助。