【发布时间】:2011-07-19 07:27:25
【问题描述】:
如果我有一个可观察的数组
foos = [{ name: "a" }, { name: "b" }, { name: "c" }]
在我的视图模型上,我想渲染以下内容:
<ul>
<li class="add-new-foo">Special stuff here</li>
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
我很接近
<ul data-bind="template: { name: 'foo-template', foreach: foos }">
<li class="add-new-foo">Special stuff here</li>
</ul>
<script id="foo-template" type="text/html">
<li data-bind="text: name"></li>
</script>
但这最终将.add-new-foo 放在 a、b、c 之后。
有什么想法吗?就我而言,使用 Knockout foreach 而不是 jQuery 模板的 {{each}} 至关重要,因为 the benefits mentioned in the Knockout docs。
【问题讨论】:
标签: jquery-templates knockout.js