john chan
john chan

Reputation: 223

how to restore back data in template using knockout.js

I want to build a template like gridview. My problem is when I edit the data '123qwe' to '123' but when i click 'cancel' button not to edit the data. the data not restore back to '123qwe'. I have a workaround to solve this, however, it is not work in my computer but in jsfiddle, I want to know the reason and help to solve in a knockout.js format. Thank you~~~

code to attention:

// Reset button
self.reset = function (index) { 
    self.nameLists([]);
    $.each(og_arr, function(i,item){
        self.nameLists.push(new nameFilter(item.name));
    });
    this.editTemplate("readOnlyTemplate");
}; 

program in jsfiddle

Upvotes: 0

Views: 53

Answers (2)

Val
Val

Reputation: 2323

For general "undo" functionality, check out the Memento plugin for Knockout.

(I didn't write it, just a satisfied user)

Upvotes: 0

Roy J
Roy J

Reputation: 43881

There is no built-in notion of canceling an edit. You are editing an observable. Have a look at protected observables, a simple extension that allows you to commit or reset a change.

Upvotes: 1

Related Questions