且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

替换observableArray中的项目

更新时间:2023-12-05 12:50:28

替换函数接受两个参数,要替换的项目以及要替换它的新项目。您正在传递索引以代替要替换的项目,因此它不起作用。

The replace function accepts two parameters, the item you want to replace and the new item you want to replace it with. You are passing in the index in place of the item to replace so it doesn't work.

替换调用应该是:

self.locations.replace(oldLocation, new location(value));

在旁注中,您不需要 valueHasMutated()在那里调用,它将被 replace()调用调用。

On a side note, you shouldn't need the valueHasMutated() call there, it will get invoked by the replace() call.