1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-04-06 03:57:53 +08:00
Zenon dc9e27e4b1 1.fix bug (#431)
* 1.fix bug
2.update treeTable readme
3.update args name in treetable/eval.js

* 1.treeTable animate
2018-01-30 09:58:25 +08:00

30 lines
775 B
JavaScript

/**
* @Author: jianglei
* @Date: 2017-10-12 12:06:49
*/
'use strict'
import Vue from 'vue'
export default function treeToArray(data, expandAll, parent = null, level = null) {
let tmp = []
Array.from(data).forEach(function(record) {
if (record._expanded === undefined) {
Vue.set(record, '_expanded', expandAll)
}
let _level = 1
if (level !== undefined && level !== null) {
_level = level + 1
}
Vue.set(record, '_level', _level)
// 如果有父元素
if (parent) {
Vue.set(record, 'parent', parent)
}
tmp.push(record)
if (record.children && record.children.length > 0) {
const children = treeToArray(record.children, expandAll, record, _level)
tmp = tmp.concat(children)
}
})
return tmp
}