javascript - Knockout not mapping correctly manually -


i trying read json snippet oberservable array in knockout.js, reason properties of contactgroup object never set, can shed light on why happens? thanks!

"contactgroups":[     {"id":1,"name":"test group","contact":[{"name":"aaaaaa"},{"name":"bbbbbb"}] }]  self.contactgroups = ko.observablearray([])  $(data.contactgroups).each(function(group){     var temp = new contactgroup({id: group.id, name: group.name})     $(group.contact).each(function(contact){         var temp_contact = new contact(contact)         temp.contact.push(temp_contact)     });     self.contactgroups.push(temp); })      function contactgroup(data){         var self = this;         self.id = data.id;         self.name = ko.observable(data.name);         self.contact = ko.observablearray([]);          function contact(){             this.name = ko.observable();             this.email = ko.observable();             this.telephone = ko.observable();             this.mobile = ko.observable();             this.mail_group = ko.observable();             this.comment = ko.observable();         }                      self.addcontact = function(){             self.contact.push(new contact);         }          self.removecontact = function(){             self.contact.remove(this);         }     } 

observable arrays functions if want set observable array, should use self.contactgroups(array); instead of self.contactgroups.push(temp);

 self.map = function() {         var grouparr = [];        ko.utils.arrayforeach(this.items(), function(item) {           var temp_contact = new contact(contact)            temp.contact.push(temp_contact)            grouparr.push(temp)         });       self.contactgroups (grouparr);   } 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -