KnockoutJS - 绑定的数量不超过 HTML 中找到的第一个绑定
初学者问题:
我有一个简单的 viewModel 和几个具有简单 data-bind="text: property"
绑定的
元素。该绑定仅适用于 HTML 中的第一个这样的 data-bind
。
jsFiddle 示例: http://jsfiddle.net/clrudolphi/ucAUC/ 在示例中,我定义了 7 个带有绑定的
。前 4 个看起来像这样: <div id="eagleMain" >
<div class="eagle-num" data-bind="text: num" />
<div class="eagle-name" data-bind="text: name" />
<div class="eagle-date" data-bind="text: date" />
<div class="eagle-current" data-bind="text: current" />
</div>
脚本看起来像这样:
var eagle = {
num: '2',
name: "John",
date: "Jan 1, 2011",
current: "student",
memories: "camping",
projectName: "Clothing Drive",
projectDescription: "lorem ipsum"
};
ko.applyBindings(eagle);
接收值的唯一 div 是第一个(绑定到“num”属性)。
我做错了什么?
谢谢, 克里斯
Beginner question:
I have a simple viewModel and several <div>
elements with simple data-bind="text: property"
bindings.
The binding only works for the first such data-bind
in the HTML.
Example on jsFiddle: http://jsfiddle.net/clrudolphi/ucAUC/
In the example, I have defined 7 <div>
s with bindings. The first 4 look like this:
<div id="eagleMain" >
<div class="eagle-num" data-bind="text: num" />
<div class="eagle-name" data-bind="text: name" />
<div class="eagle-date" data-bind="text: date" />
<div class="eagle-current" data-bind="text: current" />
</div>
The script looks like this:
var eagle = {
num: '2',
name: "John",
date: "Jan 1, 2011",
current: "student",
memories: "camping",
projectName: "Clothing Drive",
projectDescription: "lorem ipsum"
};
ko.applyBindings(eagle);
The only div that receives a value is the first (bound to the 'num' property).
What am I doing wrong?
Thanks,
Chris
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尽量不要使用
/>
来缩短标签。它仅适用于span
。去:
Try not short-cutting the tags using
/>
. It only works forspan
.Go for:
@nEEbz 比我先一步。
解决方案位于:
http://jsfiddle.net/fZYVb/1/
@nEEbz beat me to it.
Solution at:
http://jsfiddle.net/fZYVb/1/