Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knockout.js ViewModel change callback?

I'm trying to implement an auto-save feature in a Knockout.js app.

Is there a way to assign a callback for whenever a ViewModel changes?

like image 965
namuol Avatar asked Oct 15 '11 01:10

namuol


2 Answers

Take a look at Ryan Niemeyer's smart, dirty flag at http://www.knockmeout.net/2011/05/creating-smart-dirty-flag-in-knockoutjs.html

like image 56
photo_tom Avatar answered Nov 05 '22 10:11

photo_tom


It is straightforward to create a dependantObservable that depends on everything in your ViewModel - I assume someone will post an answer better than this one that contains code showing it.

(I would prefer if there was a built in "any change" callback, but as far as I can tell there is not.)

like image 39
Kyle Cordes Avatar answered Nov 05 '22 09:11

Kyle Cordes