流星收集挂钩更新数组中某个位置上的元素 [英] meteor collection hooks updating element on a position in array

查看:77
本文介绍了流星收集挂钩更新数组中某个位置上的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个对象:

card: { customFields [ { id, value }, {id , value } ... ] }

customFields数组位于卡的内部,包含由id和值组成的元素.

A customFields array is inside cards, which contans elements consisting of an id and a value.

现在我想更新数组中的某个元素,可以通过执行以下操作来完成:

Now i want to update a certain element inside of the array, which can be done by doing something like this:

  modifier.$set.customFields.0.value = x

但是我仅在变量中具有索引号,所以我尝试了:

but i have the number of the index only in a variable, so i tried:

const index = getTargetIndex();
modifier.$set.customFields[index].value = x

但是没有用...

我必须在修饰符中添加什么.$ set以更新此数组中的元素?

What do i have to add to the modifier.$set to update an element in this array?

替代解决方案:如果可以通过使用ID对值进行更新,则我具有数组中元素的ID.

Alternate Solution: i have the id of the element in the array if the update can be done on value by using the id.

推荐答案

找到了解决方案:

modifier.$set[`customFields.${  index  }.value`]

这篇关于流星收集挂钩更新数组中某个位置上的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆