返回参数中新增字段 disabled,后端给的值为1和2,
disabled==1时,代表该节点需要置灰,不可选中
现在需要将disabled的值,改为布尔类型;
后端给的数结构是对象类型,tree接收数组类型;
先将对象类型的数据,遍历递归,修改里面的disabled值,最后再加[ ],改为数组类型.
this.setDisabledData(res.data.data);
// 遍历递归
setDisabledData(node) {
let that = this;
node.disabled == 1 ? (node.disabled = true) : (node.disabled = false);
if (node.children && node.children.length > 0) {
node.children.forEach(child => {
that.setDisabledData(child);
});
node.children.every(child => {
child.disabled == 1 ? (child.disabled = true) : (child.disabled = false);
});
this.assignerArr = [node];
}
},
<el-form-item label="关键字" class="cx-scroll-wrap">
<el-input placeholder="输入关键字进行过滤" v-model="filterText" clearable></el-input>
<div class="addScrollClass " :style="{ height: tableHeight }">
<el-tree
icon-class="none"
:data="assignerArr"
:check-strictly="false"
show-checkbox
default-expand-all
node-key="id"
ref="tree"
:filter-node-method="filterNode"
highlight-current
:expand-on-click-node="false"
:props="props"
>
<span class="custom-tree-node" slot-scope="{ node, data }">
<span>
<i v-if="data.type == 2" class="el-icon-coin cx-icon"></i>
<i v-else class="el-icon-user-solid cx-icon"></i>
{{ node.label }}
</span>
</span>
</el-tree>
</div>
</el-form-item>
props: {
label: "displayName",
children: "children",
isLeaf: "leaf",
disabled: "disabled",
},