javascript - Knockout ko.mappings.fromJS not working -


i trying use knockout mapping, isn't working expected. here created simpliest fiddle can , it's not working.

am missing something?

https://jsfiddle.net/p48d11j5/1/

function model(){     var self = this;      self.id = ko.observable(0);     self.name = ko.observable("default");     self.visible = ko.observable(false);     self.items = ko.observablearray([]); }  function modelitem(){     var self = this;      self.id = ko.observable(0);     self.name = ko.observable("default item name") }  var m = new model();  ko.mapping.fromjs({     id:1,     name: "test",     visible: true,     items: [     {         id:1,         name:"first"     },     {         id:2,         name:"second"     }   ] }, m);  ko.applybindings(m); 

edit: working nested arrays, added array

edit2: want have models "typed" use functions or ko.computed properties of them

if call ko.mapping.fromjs 2 arguments :
ko.mapping.fromjs(data, mappedobject) second argument mappedobject created.then second argument taken viewmodel not options.

have is: ko.mapping.fromjs(data, {}, viewmodel) - 1 place data in model

ko.mapping.fromjs({     id:1,     name: "test",     visible: true,     items: [{id:1,name:"first"},{id:2,name:"second"}]   }, {} ,m);  // pass second argument empty object. 

Comments