鍍金池/ 問答/HTML/ element tree樹怎么編輯

element tree樹怎么編輯

有完整的例子嗎?官方文檔只有添加刪除,么有編輯功能,這個怎么編輯

官方只有增刪
clipboard.png

回答
編輯回答
淺時光

點擊以后,取出當(dāng)前節(jié)點,然后用另外的form,提交之后用代碼把修改覆蓋到樹綁定的對象里。這是我的做法


<el-tree 
ref="tree"
:props="props"
:load="loadChild"
lazy
@current-change="SwitchNode"
:accordion="true"
style="max-height:800px;min-height:400px;background-color:rgba(0,0,0,0.005);box-shadow:0 0 4px 0 #999 inset;padding:10px;user-select:none"
>
</el-tree>

這是獲取選中的node

SwitchNode(data,node){
    this.form.id = data.Id;
    this.form.label = data.label;
    this.form.node = node;
},

這是更新的:

async UpdateLabel(){
    if(this.form.NewName.length===0){
        this.$eve.emit("error","不能為空");
        return;
    }
    let node = this.form.node;
    let name = this.form.NewName;
    let res= await this.$api("sys_department",{cmd:"updatelabel",id:this.form.id,name});
    if(res.status === 200){
        node.data.label = name;
        this.form.NewName = "";
        this.form.label = name;
        this.$eve.emit("success","修改成功");
    }else{
        this.$eve.emit("error",res.msg);
    }
},

我在Form那個對象里直接把node拿到了,所以直接用node.data.label = str就可以更新了

2018年9月6日 11:30