【发布时间】:2014-06-23 06:12:06
【问题描述】:
我使用带有模板插件的 knockoutjs (Using Underscore Template with Knockout using interpolate due to asp.net) 如果我有一个标题和一个列表:
<ul data-bind="template: { name: 'people' }"></ul>
<script type="text/html" id="people">
<h2>{{= hdr}}</h2>
{{ _.each(people(), function(item) { }}
<li>{{=item.name }} ({{=item.age }})</li>
{{ }); }}
</script>
也是一个按钮
<button id="bindclick">Click</button>
还有一个我使用淘汰赛的 ja 代码:
ko.applyBindings({
hdr: "People",
people: ko.observableArray([{name:"name1",age: 45},{name:"name2",age: 33}])
});
怎么做,可以通过单击按钮而不是“未捕获的错误:您不能将绑定多次应用于同一元素。”来更改模板值?:
$("#bindclick").click(function() {
ko.applyBindings({
hdr: "People2",
people: ko.observableArray([{name:"name1",age: 45}])
});
});
谢谢
【问题讨论】: