el-cascader内部是数组形式的,而大部分接口只需传入数组的最后一个字段,但修改时候往往也只返回这最后一个字段,导致el-cascader无法正确回显
我们只需要在获取到返回的字段后传入下面这个函数即可完成el-cascader的回显
getParentsById(list, id) {
for (let i in list) {
if (list[i].no == id) {//这里的no根据你的需求可进行改变
//查询到就返回该数组对象的value
return [list[i].no];
}
if (list[i].children) {
let node = this.getParentsById(list[i].children, id);
if (node !== undefined) {
//查询到把父节把父节点加到数组前面
node.unshift(list[i].no);
return node;
}
}
}
},
注:提交时可用下面这个方法获取el-cascader数组的最后一个字段
this.$refs["你的el-cascader的ref值"].getCheckedNodes()[0].value