knockout.js - knockoutjs updated the table after edit -
how update table after upate done. heres sample code. if click update table not updating.
self.updatecategory = function(category){ var r = confirm("are sure want update category " + self.id() + "?"); if(r==true){ //code here? } };
http://jsfiddle.net/comfreakph/2trjf/3/
there couple of things need do. first off, utilize knockout mapping plugin, , set categories property using that:
self.categories = ko.mapping.fromjs(category);
your code making array observable, not each item in it. using mapping plugin, create each category , properties observable.
then need update update function original category out , update values on it:
self.updatecategory = function (category) { var r = confirm("are sure want update category " + self.id() + "?"); if (r == true) { var original = ko.utils.arrayfirst(self.categories(), function (item) { homecoming category.id() == item.id(); }); console.log(original.createdat()); original.name(self.name()); original.remarks(self.remarks()); self.name(""); self.remarks(""); self.isselected(true); } };
you should find row in table automatically updated when alter values.
jsfiddle available.
knockout.js
No comments:
Post a Comment