1.fix bug
2.update treeTable readme 3.update args name in treetable/eval.js
This commit is contained in:
		@@ -4,11 +4,11 @@
 | 
			
		||||
*/
 | 
			
		||||
'use strict'
 | 
			
		||||
import Vue from 'vue'
 | 
			
		||||
export default function treeToArray(data, expandedAll, parent = null, level = null) {
 | 
			
		||||
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', expandedAll)
 | 
			
		||||
      Vue.set(record, '_expanded', expandAll)
 | 
			
		||||
    }
 | 
			
		||||
    let _level = 1
 | 
			
		||||
    if (level !== undefined && level !== null) {
 | 
			
		||||
@@ -21,7 +21,7 @@ export default function treeToArray(data, expandedAll, parent = null, level = nu
 | 
			
		||||
    }
 | 
			
		||||
    tmp.push(record)
 | 
			
		||||
    if (record.children && record.children.length > 0) {
 | 
			
		||||
      const children = treeToArray(record.children, expandedAll, record, _level)
 | 
			
		||||
      const children = treeToArray(record.children, expandAll, record, _level)
 | 
			
		||||
      tmp = tmp.concat(children)
 | 
			
		||||
    }
 | 
			
		||||
  })
 | 
			
		||||
 
 | 
			
		||||
@@ -58,7 +58,7 @@ export default {
 | 
			
		||||
        tmp = this.data
 | 
			
		||||
      }
 | 
			
		||||
      const func = this.evalFunc || treeToArray
 | 
			
		||||
      const args = this.evalArgs ? Array.concat([tmp], this.evalArgs) : [tmp, this.expandAll]
 | 
			
		||||
      const args = this.evalArgs ? Array.concat([tmp, this.expandAll], this.evalArgs) : [tmp, this.expandAll]
 | 
			
		||||
      return func.apply(null, args)
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
 
 | 
			
		||||
@@ -70,11 +70,11 @@
 | 
			
		||||
#### evalArgs
 | 
			
		||||
  解析函数的参数,是一个数组
 | 
			
		||||
 | 
			
		||||
  **请注意,自定义的解析函数参数第一个为this.data,你不需要在evalArgs填写。** *this.data为需要解析的数据*
 | 
			
		||||
  **请注意,自定义的解析函数参数第一个为this.data,第二个参数为, this.expandAll,你不需要在evalArgs填写。一定记住,这两个参数是强制性的,并且位置不可颠倒** *this.data为需要解析的数据,this.expandAll为是否默认展开*
 | 
			
		||||
 | 
			
		||||
  如你的解析函数需要的参数为`(this.data,1,2,3,4)`,那么你只需要将`[1,2,3,4]`赋值给`evalArgs`就可以了
 | 
			
		||||
  如你的解析函数需要的参数为`(this.data, this.expandAll,1,2,3,4)`,那么你只需要将`[1,2,3,4]`赋值给`evalArgs`就可以了
 | 
			
		||||
  
 | 
			
		||||
  如果你的解析函数参数只有一个`(this.data)`,那么就可以不用填写evalArgs了
 | 
			
		||||
  如果你的解析函数参数只有`(this.data, this.expandAll)`,那么就可以不用填写evalArgs了
 | 
			
		||||
  
 | 
			
		||||
  具体可参考[*customEval.js*](https://github.com/PanJiaChen/vue-element-admin/blob/master/src/views/example/table/treeTable/customEval.js)的函数参数和[customTreeTable](https://github.com/PanJiaChen/vue-element-admin/blob/master/src/views/example/table/treeTable/customTreeTable.vue)的`evalArgs`属性值
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,12 +4,12 @@
 | 
			
		||||
*/
 | 
			
		||||
'use strict'
 | 
			
		||||
import Vue from 'vue'
 | 
			
		||||
export default function treeToArray(data, parent, level, expandedAll, item) {
 | 
			
		||||
export default function treeToArray(data, expandAll, parent, level, item) {
 | 
			
		||||
  const marLTemp = []
 | 
			
		||||
  let tmp = []
 | 
			
		||||
  Array.from(data).forEach(function(record) {
 | 
			
		||||
    if (record._expanded === undefined) {
 | 
			
		||||
      Vue.set(record, '_expanded', expandedAll)
 | 
			
		||||
      Vue.set(record, '_expanded', expandAll)
 | 
			
		||||
    }
 | 
			
		||||
    let _level = 1
 | 
			
		||||
    if (level !== undefined && level !== null) {
 | 
			
		||||
@@ -40,7 +40,7 @@ export default function treeToArray(data, parent, level, expandedAll, item) {
 | 
			
		||||
    }
 | 
			
		||||
    tmp.push(record)
 | 
			
		||||
    if (record.children && record.children.length > 0) {
 | 
			
		||||
      const children = treeToArray(record.children, record, _level, expandedAll, item)
 | 
			
		||||
      const children = treeToArray(record.children, expandAll, record, _level, item)
 | 
			
		||||
      tmp = tmp.concat(children)
 | 
			
		||||
    }
 | 
			
		||||
  })
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,7 @@
 | 
			
		||||
      <a href="https://github.com/PanJiaChen/vue-element-admin/tree/master/src/components/TreeTable" target="_blank">Documentation</a>
 | 
			
		||||
    </el-tag>
 | 
			
		||||
 | 
			
		||||
    <tree-table :data="data" :evalFunc="func" :evalArgs="args" border>
 | 
			
		||||
    <tree-table :data="data" :evalFunc="func" :evalArgs="args" :expandAll="expandAll" border>
 | 
			
		||||
      <el-table-column label="事件">
 | 
			
		||||
        <template slot-scope="scope">
 | 
			
		||||
          <span style="color:sandybrown">{{scope.row.event}}</span>
 | 
			
		||||
@@ -48,6 +48,7 @@ export default {
 | 
			
		||||
  data() {
 | 
			
		||||
    return {
 | 
			
		||||
      func: treeToArray,
 | 
			
		||||
      expandAll: false,
 | 
			
		||||
      data:
 | 
			
		||||
        {
 | 
			
		||||
          id: 1,
 | 
			
		||||
@@ -123,7 +124,7 @@ export default {
 | 
			
		||||
            }
 | 
			
		||||
          ]
 | 
			
		||||
        },
 | 
			
		||||
      args: [null, null, true, 'timeLine']
 | 
			
		||||
      args: [null, null, 'timeLine']
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user