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

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -