element tree树怎么编辑

有完整的例子吗?官方文档只有添加删除,么有编辑功能,这个怎么编辑

官方只有增删
clipboard.png

阅读 5.4k
1 个回答

点击以后,取出当前节点,然后用另外的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就可以更新了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题