1.fix bug

2.update treeTable readme
3.update args name in treetable/eval.js
This commit is contained in:
lei.jiang 2018-01-29 21:38:08 +08:00
parent d754eae662
commit 9e2d3b69ad
5 changed files with 13 additions and 12 deletions

View File

@ -4,11 +4,11 @@
*/ */
'use strict' 'use strict'
import Vue from 'vue' 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 = [] let tmp = []
Array.from(data).forEach(function(record) { Array.from(data).forEach(function(record) {
if (record._expanded === undefined) { if (record._expanded === undefined) {
Vue.set(record, '_expanded', expandedAll) Vue.set(record, '_expanded', expandAll)
} }
let _level = 1 let _level = 1
if (level !== undefined && level !== null) { if (level !== undefined && level !== null) {
@ -21,7 +21,7 @@ export default function treeToArray(data, expandedAll, parent = null, level = nu
} }
tmp.push(record) tmp.push(record)
if (record.children && record.children.length > 0) { 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) tmp = tmp.concat(children)
} }
}) })

View File

@ -58,7 +58,7 @@ export default {
tmp = this.data tmp = this.data
} }
const func = this.evalFunc || treeToArray 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) return func.apply(null, args)
} }
}, },

View File

@ -70,11 +70,11 @@
#### evalArgs #### 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`属性值 具体可参考[*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`属性值

View File

@ -4,12 +4,12 @@
*/ */
'use strict' 'use strict'
import Vue from 'vue' import Vue from 'vue'
export default function treeToArray(data, parent, level, expandedAll, item) { export default function treeToArray(data, expandAll, parent, level, item) {
const marLTemp = [] const marLTemp = []
let tmp = [] let tmp = []
Array.from(data).forEach(function(record) { Array.from(data).forEach(function(record) {
if (record._expanded === undefined) { if (record._expanded === undefined) {
Vue.set(record, '_expanded', expandedAll) Vue.set(record, '_expanded', expandAll)
} }
let _level = 1 let _level = 1
if (level !== undefined && level !== null) { if (level !== undefined && level !== null) {
@ -40,7 +40,7 @@ export default function treeToArray(data, parent, level, expandedAll, item) {
} }
tmp.push(record) tmp.push(record)
if (record.children && record.children.length > 0) { 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) tmp = tmp.concat(children)
} }
}) })

View File

@ -5,7 +5,7 @@
<a href="https://github.com/PanJiaChen/vue-element-admin/tree/master/src/components/TreeTable" target="_blank">Documentation</a> <a href="https://github.com/PanJiaChen/vue-element-admin/tree/master/src/components/TreeTable" target="_blank">Documentation</a>
</el-tag> </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="事件"> <el-table-column label="事件">
<template slot-scope="scope"> <template slot-scope="scope">
<span style="color:sandybrown">{{scope.row.event}}</span> <span style="color:sandybrown">{{scope.row.event}}</span>
@ -48,6 +48,7 @@ export default {
data() { data() {
return { return {
func: treeToArray, func: treeToArray,
expandAll: false,
data: data:
{ {
id: 1, id: 1,
@ -123,7 +124,7 @@ export default {
} }
] ]
}, },
args: [null, null, true, 'timeLine'] args: [null, null, 'timeLine']
} }
}, },
methods: { methods: {