Use the el-tree component setCheckedKeys of element-ui to set an invalid solution/setCheckedNodes cannot set the data

Use the el-tree component setCheckedKeys of element-ui to set an invalid solution/setCheckedNodes cannot set the data 

When we use el-tree, echo is often involved, and sometimes how to solve the failure of echo, the following are the two echo methods I commonly use

The first:

  const filterA = ['1','2'];//数组里是数字还是字符串都无所谓,只要id是真的,方法都有效
 this.$refs.tree1.setCheckedNodes(filterA);

            

The second type:


          filterA.forEach(item => {
            this.$nextTick(() => {
              this.$refs.tree2.setChecked(item, true, false);
            });
          });

Note: Make sure that the data in the tree selector is first obtained with the above code

 async mounted() {
   await this.getOrgList();//优先树形数据
   
    this.getMessageDetail();//然后执行回显
   
    }

  },

Regarding the disabling of el-tree, you only need to add a disabled parameter to the data you want to prohibit selection or deselection

res.data.data.receiveDepList.forEach(item=>{item.disabled=true;});
res.data.data.copyDepList.forEach(item=>{item.disabled=true;});

Regarding the selected item staying empty, the parameter can only be an array

 this.$refs.tree1.setCheckedNodes([]);

Guess you like

Origin blog.csdn.net/aZHANGJIANZHENa/article/details/130623244