递归反序列化对象中的某个属性
反序列化是进行大量数据操作时候经常用到的知识点,因此做此记录,以期复用。
// 递归解耦 addition
const parseList = (list:any[]) => {
for (let i = 0, len = list.length; i < len; i++) {
if (typeof list[i].addition === 'string') {
list[i].addition = JSON.parse(list[i].addition)
}
if (list[i].children && list[i].children.length) {
list[i].children = parseList(list[i].children)
}
}
return list
}