如何在淘汰表中替换给定的索引元素 [英] How to replace a given index element in knockoutjs
本文介绍了如何在淘汰表中替换给定的索引元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何用另一个元素替换observableArray中的给定索引.
How do you replace a given index in an observableArray with another element.
我有:
ViewModel.Elements()[index]
我如何用另一个元素替换它.
how can i replace it with another element.
推荐答案
observableArrays确实具有replace
方法.这将接收旧项目和新项目.
observableArrays do have a replace
method. This takes in the old item and the new item.
因此,您可以这样称呼它:
So, you would call it like:
ViewModel.Elements.replace(ViewModel.Elements()[index], yourNewElement);
在内部,这只是将索引设置为您的新商品,并调用valueHasMutated()来通知任何潜在的订阅者.
Internally, this just sets that index to your new item and calls valueHasMutated() to notify any potential subscribers.
这篇关于如何在淘汰表中替换给定的索引元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文