使用Ramda.js(和镜头),我想修改下面的JavaScript对象,将具有ID ="/ 1/B/i"的对象的"NAME:VERSION1"更改为"NAME:VERSION2".
我想使用镜头,因为我只想更改一个深度嵌套的值,但保持整个结构不变.
我不想使用lensIndex,因为我永远不知道数组的顺序,所以相反,我想通过查找它的"id"字段来"找到"数组中的对象.
我可以用镜头做这个,还是应该用不同的方式做?
{
"id": "/1",
"groups": [
{
"id": "/1/A",
"apps": [
{
"id": "/1/A/i",
"more nested data skipped to simplify the example": {}
}
]
},
{
"id": "/1/B",
"apps": [
{ "id": "/1/B/n", "container": {} },
{
"id": "/1/B/i",
"container": {
"docker": {
"image": "NAME:VERSION1",
"otherStuff": {}
}
}
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)