我有一个结构,像这样
[{
title: "Section 1",
items: [{
title: 'Dashboard',
icon: 'tachometer-alt',
route: '/dashboard',
opened: false
},
{
title: 'Appointments',
icon: 'calendar-alt',
route: '/appointments',
opened: true
},
{
title: 'Orders',
icon: 'box',
route: '/orders',
opened: false,
children: [{
title: 'Orders submenu 1',
route: '/orders/sub1',
opened: false,
children: [{
title: 'Orders submenu 1 subsubmenu 1',
route: '/orders/sub1/sub1sub1'
}]
}]
}
]
}]这些基本上是带有菜单项的部分,每个菜单项都可以包含子菜单,子菜单有子菜单,等等。
我有一个切换函数,它得到一个属性数组。我想否定由这个数组“标记”的变量,所以当我得到一个[0, 'items', 2, 'children', 0, 'opened']数组时,预期的行为是"Orders子菜单1“将其”打开“属性设置为"true”。
属性索引器数组也是可变的,所以如果需要的话,我可以稍微调整一下。
使用Ramda,我可以轻松地获得R.path([0, 'items', 1, 'opened'], menu)的当前值,但是如何将其设置为"true“呢?
发布于 2018-08-15 07:28:14
你可以利用兰达的镜头来实现这一点。
const togglePath = (path, obj) => R.over(R.lensPath(path), R.not, obj)
togglePath([0, 'items', 1, 'opened'], menu)https://stackoverflow.com/questions/51854211
复制相似问题