0

以下数据在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>

但是,没有任何输出,没有显示列表项。

4

1 回答 1

2

使用此官方教程http://learn.knockoutjs.com/#/?tutorial=collections中的示例创建的小提琴

http://jsfiddle.net/vgYC7/

这就是 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());
于 2013-01-19T16:50:54.817 回答