javascript - KnockoutJS - Mapping and Extenders -


i'm trying implement kind of undo feature in project using knockoutjs. purpose, i'm using extender:

ko.extenders.trackchange = function (target, track) {     if (track) {         target.isdirty = ko.observable(false);         target.originalvalue = target();         target.subscribe(function (newvalue) {              // push "states" array js representation of viewmodel             // can stack of changes             states.push(ko.tojs(track.myviewmodel));              target.isdirty(newvalue != target.originalvalue);                            target.originalvalue = newvalue;          });     }     return target; };   

then apply extender object viewmodel:

this.myviewmodel = {     label: ko.observable("label").extend({ trackchange: }); } 

and when want undo action, this:

ko.applybindings(ko.mapping.fromjs(states[statespointer])); 

this ok in order old values, extend function in observable lost new changes not saved in "states" stack.

suggestions?

thanks in advance, elian.

i think should not create new model instance performing undo op, just update observable properties of existing model:

// do: // ko.applybindings(ko.mapping.fromjs(states[statespointer]));  // do: ko.mapping.fromjs(states[statespointer], myviewmodel); 

looks myviewmodel has own context, have modify code correct ref model.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -