Repository navigation
Expand file tree
/
Copy pathtree.dirctive.js
More file actions
128 lines (121 loc) · 4.3 KB
/
Copy pathtree.dirctive.js
File metadata and controls
128 lines (121 loc) · 4.3 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
app.directive('tree', function ($http) {
return {
restrict: 'E',
replace: true,
scope: {
treeParam: "="
},
templateUrl: "template/tree.html",
link: function (scope, elem, attr) {
$http.get('./tree1.json').then(function (res) {
scope.list = rendar(res.data);
})
//编辑修改操作
scope.tree_edit = function (data) {
data.isEdit = !data.isEdit;
if (!data.isEdit) {
//这里进行修改操作。
}
}
//删除操作
scope.del = function (id) {
eachDel(scope.list, id);
}
//展开,收起
scope.Allstatus = function(is){
All(scope.list,is,'status')
}
//全选操作
scope.All = function (is) {
if (is) {
All(scope.list,true,'ischeckbox');
} else {
All(scope.list,false,'ischeckbox');
}
}
function All(data,is,prs){
data.forEach(function(e){
e[prs]=is;
if(e.children){
All(e.children,is,prs)
}
})
}
function eachis(data, param) {
var prs = param;
for (var i = 0; i < data.length; i++) {
// if(data[i][prs])
}
}
function eachDel(data, delId,prent) {
console.log(delId)
for (var i = 0; i < data.length; i++) {
if (data[i].id == delId) {
if (data[i].children.length > 0) {
if (window.confirm('检测到当前类别下有子级,确定要删除吗?(删除后,当前所以子级消失)')) {
data.splice(i, 1);
alert("删除成功!");
return false;
}
} else {
data.splice(i, 1);
if(!prent.children.length>0){
prent.status=null;
}
alert("删除成功!");
return false;
}
} else {
if (data[i].children.length > 0) {
eachDel(data[i].children, delId,data[i]);
}
}
}
return data
}
//添加子类操作
scope.addchildren = function (data,name) {
if (data == 0) {
if (name.length > 0) {
var obj = new Object();
obj.name = name;
obj.id = parseInt(Math.random()*1000);
obj.children = []
scope.list.push(obj)
scope.newTop="";
} else {
return false;
}
} else {
if (name.length > 0) {
var obj = new Object();
obj.name = name;
obj.id = parseInt(Math.random()*1000);
obj.children = []
data.children.push(obj)
data.add = false;
} else {
return false;
}
}
}
/**
* 递归,将每条数据附上状态
* status:用来管理展开收缩
* isEdit:用来管理是否编辑
*/
function rendar(data) {
data.forEach(function (i) {
i.isEdit = false;
i.ischeckbox = false;
if (i.children && i.children.length > 0) {
i.status = false;
i.add=false;
rendar(i.children);
}
})
return data;
}
}
}
})