【发布时间】:2016-06-02 23:26:38
【问题描述】:
使用 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": {}
}
}
}
]
}
]
}
【问题讨论】:
标签: javascript ramda.js lenses