Book Image

KnockoutJS Web Development

Book Image

KnockoutJS Web Development

Overview of this book

Table of Contents (13 chapters)
KnockoutJS Web Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Enhanced collection handling


In our first segment, native templates, we focused on single sets of data. In JavaScript, we often have collections of data stored in arrays. We will be including an example here to show how to use templates stored in arrays.

We can copy the data from our last example page to this page. We will be using more of the structure this time around. We will start by focusing on the speakers. This array contains structured items for each speaker. The code section of our script tag should look like this:

vm = ko.mapping.fromJS(mySeminar);
ko.applyBindings( vm );

If you think this looks basically the same as the last example of code, you are right. It will change soon, but we are looking to make a point here. Arrays and non-arrays are not coded differently for routine binding functionality. Here is the segment of data that we will be using for this part of the exercise:

speakers : [
  { id: 1, name: "John Doe", bio: 'This is the bio for John.',
    skills: [ "jQuery","KnockoutJS...