以下数据位于ko.observableArray
汽车中:(这是数组的转储)
[
{
"carId": 1,
"carName": "Ford",
"carStatus": "On-Hold",
"carDescription": "This is the first car description."
},
{
"carId": 1,
"carName": "Toyota",
"carStatus": "On-Hold",
"carDescription": "This is the second car description."
}
]
查看
<ul data-bind="foreach: cars()">
<li>
<span data-bind="text: carDescription"></span>
</li>
</ul>
但是,没有输出任何内容,也没有显示列表项。
答案 0 :(得分:2)
使用此官方教程http://learn.knockoutjs.com/#/?tutorial=collections
中的示例创建了小提琴这就是ViewModel所需要的全部内容
function ViewModel() {
var self = this;
// Editable data
self.cars = ko.observableArray([
{
"carId": 1,
"carName": "Ford",
"carStatus": "On-Hold",
"carDescription": "This is the first car description."
},
{
"carId": 1,
"carName": "Toyota",
"carStatus": "On-Hold",
"carDescription": "This is the second car description."
}
]);
}
ko.applyBindings(new ViewModel());