用递归算法来清空和设置状态
2017-08-31 本文已影响0人
坠入莱茵河
Object.keys(obj).forEach((item, idx) => {
if (typeof obj[item] === 'object') {
if (obj[item].active) obj[item].active = false
recursion(obj[item])
}
})
let recursion = (obj) => {
Object.keys(obj).forEach((item, idx) => {
if (typeof obj[item] === 'object') {
obj[item].active = false
recursion(obj[item])
} else if (typeof obj[item] === 'string') {
obj[item] = {
value: obj[item],
active: false
}
}
})
}
recursion(res.data)