更新 observableArray 不会更新 UI
我在 ko 2.0 中使用无容器流量控制。当我更新 observableArray 中的项目时,它不会更新 UI。我正在像这样更新数组:
this.editFormHost = function (formHost) {
...
formHost.HostName = newHostName;
this.formHosts[index] = formHost;
}
我认为它不会更新,因为按索引更新数组不会调用 ko.从文档来看,似乎没有方法可以更新对象,从而更新 UI。或者有吗?
I am using the containerless flow control in ko 2.0. When I update an item in my observableArray it is not updating the UI. I am updating the array like this:
this.editFormHost = function (formHost) {
...
formHost.HostName = newHostName;
this.formHosts[index] = formHost;
}
I am thinking it doesn't update because updating the array by index does not call anything in ko. From looking at the documentation it looks like there are no methods to update an object which will in turn update the UI. Or is there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个小提琴,演示了如何替换 observableArray 中的项目并将其更改通知 UI。
http://jsfiddle.net/johnpapa/ckMJE/
这里的关键是 observableArray 上的替换函数。您也可以使用拼接。
...注意下面“替换”的使用...
Here is a a fiddle that demonstrates how to replace an item in an observableArray and have its changes notify the UI.
http://jsfiddle.net/johnpapa/ckMJE/
The key here is the replace function on the observableArray. You could also use splice.
... Notice the use of "replace" below ...