knockout.js - Knockout JS: how to update a whole observable array -


i need little knockout js.

i have todo-list type web-app , need update on demand whole observable array contain task list data fetched database.

i have created sample fiddle here: http://jsfiddle.net/ingro/43xcu/26/

self.update = function(){      var values = [         {time: "17:00", title: "test#11"},         {time: "18:00", title: "work#22"},              {time: "19:00", title: "task#33"},             {time: "20:00", title: "sleep#14"}     ];      self.clone = ko.observablearray(ko.utils.arraymap( values , function( clone) {         return new post(clone.time, clone.title);     }));      var count = 0;      ko.utils.arrayforeach(self.posts(), function(post) {         post.time(self.clone()[count].time());         post.title(self.clone()[count].title());         count++;     });             } 

data in "values" simulate json response server. way made work creating clone observable array , cycle through real 1 , update elements 1 one new values. isn't optimal solution many reasons, example if number of elements in 2 arrays not equal , on.

so can suggest me better way update it?

thanks , sorry awful english :d

i'm not sure it's absolutly need did using knockout mapping plugin: http://knockoutjs.com/documentation/plugins-mapping.html

you can try fiddle here: http://jsfiddle.net/chubyone/a682w/6/

regards.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -