Wednesday, 15 February 2012

knockout.js - Knockout auto mapping with unnamed array and adding an isDirty property -


I am using the knockout mapping plugin I am the simplified Jason as an unknown array. {"Id": 1, "title": "title1"}, {"id": 2, "title": "title 2"}, {"id": 3, "title": "title 3"}]

My view-model to keep a named "item" property, I am assigning this way: var model = {item: to.mapping.fr JS (Jessondata, Mapping Option)}

There is a problem connecting isDirty property during the mapping process I am surprised if I am delivering it incorrectly Uje is triggered.

UPDATE

Here is the work based on the answer given below.

The issue you see in your Bela is that your "making" does not call your mapping method

You defined your mapping as the

  var mapping option = {item: {create: function (mappingoptions) {...}} };   

So a.map is looking for an array of your item object that is called "item", it will run the "Create" method on each item. However, your data object "jsn" does not have a collection of "item" names. "ja" Code>

If you change your jsondata:

  var jsondata = {items: ["id": 1, "title": "title1"}, {"ID": 2, "Title": "Heading 2"}}}   

You should see the execution of the "create" method and your third flag will be added.

You can also change your mapping to eliminate "item":

  var mappingopspings = {create: function (mapping option) {...}} ;   

Hope it helps!

No comments:

Post a Comment