【发布时间】:2021-02-24 04:22:12
【问题描述】:
我有一个一维嵌套数组:
nestedObj: [
{ id: 1, parentId: null, taskCode: '12', taskName: 'Parent', duration: 0, assignee: '', crewCount: 0, startDate: null, endDate: null, dependencies: []},
{ id: 2, parentId: 1, taskCode: '12100', taskName: 'Child one', duration: 0, assignee: '', crewCount: 0, startDate: null, endDate: null, dependencies: []},
{ id: 3, parentId: 2, taskCode: '12200', taskName: 'SubChild one', duration: 0, assignee: '', crewCount: 0, startDate: null, endDate: null, dependencies: []},
{ id: 4, parentId: 1, taskCode: '12200', taskName: 'Child two', duration: 0, assignee: '', crewCount: 0, startDate: null, endDate: null, dependencies: []}
]
根据上述数据结构,taskName 的树状图如下所示
-> Parent
-> Child one
-> SubChild one
-> Child two
这是我的问题:当我更新孩子的startDate 时,其直接父母的startDate 应该更新为最小的startDate(在其所有孩子中),并且这个过程应该传播到根。反之亦然endDate(即)最大startDate(所有子代)。如何使用递归实现这一点?
注意:假设日期为时间戳
提前致谢
【问题讨论】:
-
这个问题有点宽泛。您在尝试编码时遇到了什么问题?
-
结构太平了,我都在努力写递归调用的函数
标签: javascript html vue.js recursion