treeData: [
{
MenuName: "信息",
MenuID: 1,
menuChildList: [
{
MenuName: "个人信息",
MenuID: "2",
menuChildList: [
{
MenuName: "审核",
MenuID: 3,
},
{
MenuName: "编辑",
MenuID: 4,
},
],
},
],
},
],
/**
* 对多维数组的筛选
* @param query 要查询的值
* @param children 多层级树形的数组的key与查询数据比对 默认 ['label']
* @param key 多层级树形的数组的key 默认 ['children']
* @param list 多层级树形的数组
* @returns {Array}
*/
filterArrayData(query, key, children, list) {
var filterObj = function (item) {
if (item[key].indexOf(query) > -1) return true;
if (item.hasOwnProperty(children)) {
item[children] = item[children].filter(function (child) {
if (child.hasOwnProperty(children)) {
return filterObj(child);
} else {
return child[key].indexOf(query) > -1;
}
});
if (item[children].length > 0) {
return true;
}
} else {
return child[key].indexOf(query) > -1;
}
};
var filter = list.filter(function (item) {
return filterObj(item);
});
console.log(JSON.stringify(filter));
this.treeData = filter;
},
searchFn() {
if (this.searchValue) {
this.filterArrayData(
this.searchValue,
"MenuName",
"menuChildList",
this.treeData
);
} else {
this.treeData = this.orgtreeData;
}
},

- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67