Knockout取消了jQuery UI对话框的更新

时间:2021-02-14 19:46:53

I have parent model person. The view model has an observable array of person. To edit/add a person i have a jQuery UI dialog (Ok/Cancel).

我有父模型人。视图模型具有可观察的人物阵列。要编辑/添加一个人,我有一个jQuery UI对话框(确定/取消)。

var viewModel = function(){
    var self = this;
    self.personEntry = ko.observable(new person());
    self.people = ko.observableArray();
    self.populatePeople = function(jsonPeopleObj){//adds person objects to people array};
};

The personEntry submodel is bound to the jQuery UI dialog using with binding. A table is produced using the foreach binding on the people observable array.

personEntry子模型使用with binding绑定到jQuery UI对话框。使用人类可观察数组上的foreach绑定生成表。

Now when I try to amend a record I call the following function on click of the row.

现在,当我尝试修改记录时,我在单击该行时调用以下函数。

function rowSelected(item,event){
    viewModel.personEntry(item);
    openDialog();
}

This opens the dialog with selected row's details on the jQuery UI dialog. However if I change a value and then press the cancel on the dialog, the table still gets amended with a new value which should not happen. Any thoughts?

这将在jQuery UI对话框中打开包含所选行详细信息的对话框。但是,如果我更改一个值,然后按对话框上的取消,表格仍然会修改一个不应该发生的新值。有什么想法吗?

I can put a sample code if required.

如果需要,我可以提供示例代码。

1 个解决方案

#1


0  

I have solved this with a bit of work around...

我通过一些工作来解决这个问题......

https://jsfiddle.net/ramkiFiddle/v29exev5/59/

https://jsfiddle.net/ramkiFiddle/v29exev5/59/

self.amendDetails = function(item, event) {
    itemProgressed = item;
    operation = 'Amend';
    var tempObj = new Person(item.Name(), item.Age());
    pageModel.personEntry(tempObj);
    $("#personEntry").dialog('open');
  }

#1


0  

I have solved this with a bit of work around...

我通过一些工作来解决这个问题......

https://jsfiddle.net/ramkiFiddle/v29exev5/59/

https://jsfiddle.net/ramkiFiddle/v29exev5/59/

self.amendDetails = function(item, event) {
    itemProgressed = item;
    operation = 'Amend';
    var tempObj = new Person(item.Name(), item.Age());
    pageModel.personEntry(tempObj);
    $("#personEntry").dialog('open');
  }