admin管理员组文章数量:1410737
I have the following HTML:
<!-- ko.foreach: properties -->
<span data-bind="text: $data.Name"></span>
<span data-bind="text: $data.Age"></span>
<!-- /ko -->
And this javascript:
function MyViewModel() {
var self = this;
self.properties = ko.observableArray([
{Name: "John", Age: 32},
{Name: "Steve", Age: 23}
]);
}
ko.applyBindings(new MyViewModel());
Here's the jsfiddle /
Why doesn't the foreach work?
I have the following HTML:
<!-- ko.foreach: properties -->
<span data-bind="text: $data.Name"></span>
<span data-bind="text: $data.Age"></span>
<!-- /ko -->
And this javascript:
function MyViewModel() {
var self = this;
self.properties = ko.observableArray([
{Name: "John", Age: 32},
{Name: "Steve", Age: 23}
]);
}
ko.applyBindings(new MyViewModel());
Here's the jsfiddle http://jsfiddle/cFB5B/
Why doesn't the foreach work?
Share Improve this question asked Apr 29, 2013 at 15:12 Mihai DabisteMihai Dabiste 15712 bronze badges 1- what about including the lib into the fiddle? – bwoebi Commented Apr 29, 2013 at 15:15
2 Answers
Reset to default 6It's ko foreach
, not ko.foreach
when binding a foreach inside a HTML ment (Note 4):
<!-- ko foreach: properties -->
<span data-bind="text: Name"></span>
<span data-bind="text: Age"></span>
<!-- /ko -->
http://jsfiddle/cFB5B/1/
Also, you don't need to use the $data, but that wasn't causing the problem.
You have a type .
to much in the foreach
declaration:
Instead
<!-- ko.foreach: properties -->
it should be
<!-- ko foreach: properties -->
本文标签: javascriptKnockout foreach not workingStack Overflow
版权声明:本文标题:javascript - Knockout foreach not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745035860a2638781.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论