Reputation: 157
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.net/cFB5B/
Why doesn't the foreach work?
Upvotes: 1
Views: 1773
Reputation: 2491
You have a type .
to much in the foreach
declaration:
Instead
<!-- ko.foreach: properties -->
it should be
<!-- ko foreach: properties -->
Upvotes: 4
Reputation: 35803
It's ko foreach
, not ko.foreach
when binding a foreach inside a HTML comment (Note 4):
<!-- ko foreach: properties -->
<span data-bind="text: Name"></span>
<span data-bind="text: Age"></span>
<!-- /ko -->
Also, you don't need to use the $data, but that wasn't causing the problem.
Upvotes: 6