我想要根据传进来的这个id值进行查找 treeDataMap 中对应的数据 并给treeDataMap重新赋值
const getTreeDataForListIInter = (id, newValue) => {
// 查找与 ID 相关联的节点
const nodeToUpdate = findNodeById(treeDataMap[Object.keys(treeDataMap)[0]], id);
// 如果找到了节点,则更新其值
if (nodeToUpdate) {
// 获取当前数据结构
const newChildren = treeDataMap[Object.keys(treeDataMap)[0]].children.map(node =>
node.value === id ? {...node, value: newValue} : node
);
setTreeDataMap({...treeDataMap, [Object.keys(treeDataMap)[0]]: {...treeDataMap[Object.keys(treeDataMap)[0]], children: newChildren}});
}
};
大概要实现的效果就是,根据的传递进去这个id值,从这个treeDataMap对象里面循环查找或者其他查找方式都可以,把属于这个id值的数据找出来 并给treeDataMap 重新进行赋值的操作。