86880ea63d14127ad66f69d3581cbe8dd9625639.svn-base 806 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. * @Author: jianglei
  3. * @Date: 2017-10-12 12:06:49
  4. */
  5. 'use strict'
  6. import Vue from 'vue'
  7. export default function treeToArray (data, expandAll, parent = null, level = null) {
  8. let tmp = []
  9. Array.from(data).forEach(function (record) {
  10. if (record._expanded === undefined) {
  11. Vue.set(record, '_expanded', expandAll)
  12. }
  13. let _level = 1
  14. if (level !== undefined && level !== null) {
  15. _level = level + 1
  16. }
  17. Vue.set(record, '_level', _level)
  18. // 如果有父元素
  19. if (parent) {
  20. Vue.set(record, 'parent', parent)
  21. }
  22. tmp.push(record)
  23. if (record.children && record.children.length > 0) {
  24. const children = treeToArray(record.children, expandAll, record, _level)
  25. tmp = tmp.concat(children)
  26. }
  27. })
  28. return tmp
  29. }