审查视图

src/components/TreeTable/eval.js 866 字节
朱兆平 authored
1
/**
2 3 4
 * @Author: jianglei
 * @Date:   2017-10-12 12:06:49
 */
朱兆平 authored
5 6
'use strict'
import Vue from 'vue'
7
朱兆平 authored
8
export default function treeToArray(data, expandAll, parent = null, level = null) {
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
    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
朱兆平 authored
30
}