我正在使用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