动态获取数据后,遍历给数组增加disabled字段,试图和element官网demo的结构相同,但是disabled并没有生效。
解决方法:后端返回的数据中增加disabled字段,再根据自身需要设置为true
for
(
var
i
=
0
;
i
<
this
.
data2
.
length
;
i
++
) {
this
.
data2
[
i
].
disabled
=
true
if
(
this
.
data2
[
i
].
children
.
length
>
0
) {
var
children
=
this
.
data2
[
i
].
children
for
(
var
j
=
0
;
j
<
children
.
length
;
j
++
) {
console
.
log
(
'children:'
+
children
[
j
].
children
.
length
)
if
(
children
[
j
].
children
.
length
>
0
) {
children
[
j
].
disabled
=
true
var
children2
=
children
[
j
].
children
for
(
var
k
=
0
;
k
<
children2
.
length
;
k
++
) {
children2
[
k
].
disabled
=
true
}
}
else
{
children
[
j
].
disabled
=
true
}
}
}
else
{
this
.
data2
[
i
].
disabled
=
true
}
}