我发现这个问题是像我相似 - Replace all elements in Knockout.js observableArray替换observableArray?
我只是有一个问题 - 如果我取代observableArray
新的内容,是否会在UI
也反映了所有的元素?
这里的情景:我有一个html
文件,该文件显示table
充满内容。这是我这取js
和html
之间绑定的数据js
代码片段 -
var table = ko.observableArray(); // {1,2,3,4,5} - UI shows 1,2,3,4,5 in the table
// now I replace all the contents
table = {6,3,8,9};
// **will the UI display the updated content, which is {6,7,8,9} in the table? Or will it still display {1,2,3,4,5}?**
在你的问题中,阵列是可观察的,其内容不是。如果您更改数组的元素,则不会更新您的UI。如果您添加/删除元素,则更新UI。以下是更多信息:http://knockoutjs.com/documentation/observableArrays.html –
是的。我的意图是删除数组中的所有内容并添加新的内容,并确保新内容反映在UI中。 – AlwaysALearner