我正在使用ko.js显示场馆表。Knockout Js绑定到具有撤消功能的编辑模式
每个场地都有一个编辑按钮,显示可编辑数据的对话框。
当按下编辑按钮时,我将场地绑定到对话框,并将数据的副本存储在撤消对象中。
当我编辑对话框中的字段时,对话框和表格都会更新。
当我取消编辑时,我将场地绑定到撤消对象状态。这会更新对话框,但不会在表格中更新。
任何想法我在做什么错在这里?
这是我的视图模型。
VenueViewModel = function(venues) {
var self = this;
var venueModal = $("#venueModal");
this.venues = ko.mapping.fromJS(venues);
this.venue = ko.observable();
this.venueUndo = null;
//Cancel an edit
this.cancel = function() {
self.venue(ko.mapping.fromJS(self.venueUndo));
venueModal.modal("hide");
}
//Edit an existing venue
this.edit = function(venue) {
self.venue(venue);
self.venueUndo = ko.mapping.toJS(venue);
venueModal.modal("show");
};
//Create a new venue
this.create = function() {
self.venue(new Venue());
venueModal.modal("show");
};
};
ko.applyBindings(new VenueViewModel(venues));
您需要明确保存更新表中项目的位置:http://jsfiddle.net/JHzQ3/您还应检查以下文章:http://www.knockmeout.net/2013/01 /simple-editor-pattern-knockout-js.html – nemesv 2013-02-10 09:39:50