将1个observable加载到另一个,但同时修改两者

时间:2013-03-13 11:47:58

标签: knockout.js

在这个函数中,我已成功将selectedItem observable传递给函数openAlertDialogueEdit。

openAlertDialogueEdit(selectedItem) {
        this.IsAlertDialogueInEditMode(true);
        this.EditingItemAlert(selectedItem);
        this.isAlertDialogueOpen(true);
    }

我正在调试应用程序,可以看到对与AlertDialogueEdit中的控件绑定的EditingItemAlert observable所做的更改已完成。但原始的selectedItem observable没有改变。我怎样才能实现这种行为。

注意,selectedItem通过以下方式传递:

 data-bind="click:function() { $parent.openAlertDialogueEdit($data)}"

1 个答案:

答案 0 :(得分:1)

这不是传递$ data的值,而不是可观察的本身吗?如果要传入observable,可以尝试为foreach中的项目指定别名,或者使用index直接从父集合中获取observable:

data-bind="click:function() { $parent.openAlertDialogueEdit($parent.observableArray()[$index])}"