样式图:
/**
* 遍历children形式数据
* @param data 需要遍历的数组
* @param callback 回调
* @param childKey children字段名
*/
eachTreeData(data, callback, childKey) {
if (!childKey) childKey = 'children'
data.forEach(d => {
if (callback(d) !== false && d[childKey]) this.eachTreeData(d[childKey], callback, childKey)
})
}
使用:
this.eachTreeData('遍历数据', data => {
console.log(data)
})