Knockoutjs: how to get notifications for all properties once

Suppose I have a ViewModel with 100 details. Currently, I need one handler that will be called if any of the details changes. Of course, I can write 100.subscribe for each property, but it seems that there is a better way. Like in C #, where you can bind to the PropertyChanged event of the model, and then select objects of interest by their names.

+5
source share
2 answers

The general answer is to create dependent access that subscribes to everything. This can be easily accomplished by executing ko.toJS(viewModel)inside the dependent object, since it will recursively unwrap all observables. You must be careful not to include yourself in the call ko.toJS, or you may end up in an endless loop.

If you are looking for something with a bit more functionality, take a look at this post .

+8
source

I think you are using KO 1.2.1. It is not so simple in this version. However, Knockout 1.3 is approaching. This is currently a beta version, but it is pretty stable. Throttling was implemented in Knockout 1.3. I think this is what you need.

1.3: http://blog.stevensanderson.com/2011/08/31/knockout-1-3-0-beta-available/

: http://jsfiddle.net/StevenSanderson/Rnmb2/1/

, , .

, , .

+1

All Articles