diff --git a/src/components/TreeTable/eval.js b/src/components/TreeTable/eval.js
index 7c137a83..1046757b 100644
--- a/src/components/TreeTable/eval.js
+++ b/src/components/TreeTable/eval.js
@@ -3,8 +3,8 @@ import Vue from 'vue'
// Flattened array
export default function treeToArray(data, children = 'children') {
let tmp = []
- data.forEach((item, idx) => {
- Vue.set(item, '_index', idx)
+ data.forEach((item, index) => {
+ Vue.set(item, '_index', index)
tmp.push(item)
if (item[children] && item[children].length > 0) {
const res = treeToArray(item[children], children)
@@ -14,8 +14,10 @@ export default function treeToArray(data, children = 'children') {
return tmp
}
-export function addAttrs(data, { parent = null, level = 0, expand = false, children = 'children', show = true, select = false } = {}) {
- data.forEach(item => {
+export function addAttrs(data, { parent = null, preIndex = false, level = 0, expand = false, children = 'children', show = true, select = false } = {}) {
+ data.forEach((item, index) => {
+ const _id = (preIndex ? `${preIndex}-${index}` : index) + ''
+ Vue.set(item, '_id', _id)
Vue.set(item, '_level', level)
Vue.set(item, '_expand', expand)
Vue.set(item, '_parent', parent)
@@ -26,6 +28,7 @@ export function addAttrs(data, { parent = null, level = 0, expand = false, child
parent: item,
level: level + 1,
expand,
+ preIndex: _id,
children,
status,
select
diff --git a/src/components/TreeTable/index.vue b/src/components/TreeTable/index.vue
index 0b15f9c2..35c3b287 100644
--- a/src/components/TreeTable/index.vue
+++ b/src/components/TreeTable/index.vue
@@ -1,6 +1,7 @@
+
0) {
- addAttrs(val, {
- expand: this.defaultExpandAll,
- children: this.defaultChildren
- })
- this.guard--
- }
+ // if (this.guard > 0) {
+ addAttrs(val, {
+ expand: this.defaultExpandAll,
+ children: this.defaultChildren
+ })
+ this.guard--
+ // }
const retval = treeToArray(val, this.defaultChildren)
this.tableData = retval
+ console.log(retval)
},
- // deep: true,
+ deep: true,
immediate: true
}
},
methods: {
+ addBrother(row, data) {
+ if (row._parent) {
+ row._parent.children.push(data)
+ } else {
+ this.data.push(data)
+ }
+ },
+ addChild(row, data) {
+ if (!row.children) {
+ this.$set(row, 'children', [])
+ }
+ row.children.push(data)
+ },
+ delete(row) {
+ const { _index, _parent } = row
+ if (_parent) {
+ _parent.children.splice(_index, 1)
+ } else {
+ this.data.splice(_index, 1)
+ }
+ },
+ getData() {
+ return this.tableData
+ },
showRow: function({ row }) {
const parent = row._parent
const show = parent ? parent._expand && parent._show : true
diff --git a/src/views/table/treeTable/customTreeTable.vue b/src/views/table/treeTable/customTreeTable.vue
index 361082db..78a94d4a 100644
--- a/src/views/table/treeTable/customTreeTable.vue
+++ b/src/views/table/treeTable/customTreeTable.vue
@@ -7,26 +7,31 @@
target="_blank"
>Documentation
-
+
-
+
-
+
+
- 支持element-ui 的扩展和多选框事件哦
+ Here is just a placeholder slot, you can display anything.
-
+
+
+
添加子菜单
+ @click="addMenuItem(scope.row,'brother',scope)"
+ >Append Brother
+
+ Append Child
+
-
- 编辑
- 删除
+
+ Edit
+ Delete
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 确定
+
+
+
+
+
+
+