我有以下 HTML:
<!-- ko.foreach: properties -->
<span data-bind="text: $data.Name"></span>
<span data-bind="text: $data.Age"></span>
<!-- /ko -->
而这个javascript:
function MyViewModel() {
var self = this;
self.properties = ko.observableArray([
{Name: "John", Age: 32},
{Name: "Steve", Age: 23}
]);
}
ko.applyBindings(new MyViewModel());
这是 jsfiddle http://jsfiddle.net/cFB5B/
为什么 foreach 不起作用?