我有一个包含复杂嵌套文档的表。每个文档的结构类似于以下示例:
{
"description": "Sample Document",
"events": [
{
"liquids": { ... },
"protocol": {
"id": "5b190c4d-6590-49a3-b9a7-69f036f45e55"
},
"schedule": { ... }
},
{
"liquids": { ... },
"protocol": {
"id": "a4353a88-6021-418f-a18c-0526550edb57",
"overrides": [
{
index: 9,
values: {
foo: "bar"
}
{
index: 7,
parentIndex: 10,
values: {
foo: 8,
bar: 9
}
}
]
},
schedule: { ... }
}
],
"id": "7c424fc3-1a58-4a4e-b1b6-8d25412a85da",
"name": "Sample Doc",
"project_id": "__ROOT__"
}
我想更新数组protocol.overrides
中第二项的属性中的一项。events
我提前知道我需要访问myTable.get($id).events(1)('protocol')('overrides')
,但我无法提前知道我需要替换嵌套数组中的哪个项目。
在这个特定示例中,假设我需要将项目替换为index: 7
, 和parentIndex: 10
(第二个项目),并且假设我想将其values
属性更改为{foo: "baz", bar: "curley"}
.
我在 reQL API 中看不到任何让我这样做的方法。changeAt
如果我知道数组索引,则可以使用它,但我没有看到一个indexOf
函数或任何类似的东西可以让我通过匹配谓词来找到索引。