這篇文章給大家分享的是有關如何解決element級聯選擇器數據回顯問題的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
element級聯選擇器數據回顯問題
對于前端小菜雞來說,被這個問題也是困擾了好久。也是百度的方法。
表單部分代碼:
<el-form-item label="部門名稱:" prop="deptId"> <el-cascader placeholder="請選擇部門" :props="depShowType" :options="deptData" filterable change-on-select v-model="SelectdeptId"> </el-cascader> </el-form-item>
data中定義:
depShowType:{
value:'id',
label:'name',
children:'nodes'
},
SelectdeptId:[],methods中:
// 編輯
handleEdit(data){
this.textShow=true;
this.textForm=data;
this.SelectdeptId=this.changeDetSelect(data.deptId,this.deptData) //數據雙向綁定
},
changeDetSelect(key,treeData){
let arr = []; // 在遞歸時操作的數組
let returnArr = []; // 存放結果的數組
let depth = 0; // 定義全局層級
// 定義遞歸函數
function childrenEach(childrenData, depthN) {
for (var j = 0; j < childrenData.length; j++) {
depth = depthN; // 將執行的層級賦值 到 全局層級
arr[depthN] = (childrenData[j].id);
if (childrenData[j].id == key) {
returnArr = arr.slice(0, depthN+1); //將目前匹配的數組,截斷并保存到結果數組,
break
} else {
if (childrenData[j].nodes) {
depth ++;
childrenEach(childrenData[j].nodes, depth);
}
}
}
return returnArr;
}
return childrenEach(treeData, depth);
},感謝各位的閱讀!關于“如何解決element級聯選擇器數據回顯問題”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。