javascript - Observe MyArray().length knock out -
is possible store length on observable array in observable variable , bind view, this?
self.myarray = ko.observablearray([]); self.myarraylength = self.myarray().length; //bind in view self.observelength = ko.observable(self.myarraylength);
when alert myarray length seems update proper, cant update in view?
because myarraylength isn't observable, won't update when observable does. need computed function instead.
you should have:
self.myarray = ko.observablearray([]); // bind in view self.observelength = ko.computed(function(){ return self.myarray().length; });
Comments
Post a Comment