0

The following data is in ko.observableArray cars: (this is the dump of the array)

[
  {
    "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."
  }
]

View

<ul data-bind="foreach: cars()">
    <li>       
        <span data-bind="text: carDescription"></span>    
   </li>
</ul>

However, nothing is output, there are no list items showing.

2
  • 2
    Can you maybe put together a JSFiddle which shows your issue? But the foreach: cars() feels strange because foreach unwraps observable automatically. Try with <ul data-bind="foreach: cars"> Commented Jan 18, 2013 at 16:47
  • While the use of foreach: cars(), instead of foreach: cars, is not recommended it won't prevent rendering. Here is a fiddle that shows it working: jsfiddle.net/jearles/UzC38 Commented Jan 19, 2013 at 16:45

1 Answer 1

2

Fiddle created using samples from this official tutorial http://learn.knockoutjs.com/#/?tutorial=collections

http://jsfiddle.net/vgYC7/

And this is all you need to have for 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());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.