詳解關(guān)于element級(jí)聯(lián)選擇器數(shù)據(jù)回顯問題
更新時(shí)間:2019年02月20日 11:14:35 作者:來一杯牛奶
這篇文章主要介紹了詳解關(guān)于element級(jí)聯(lián)選擇器數(shù)據(jù)回顯問題,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
element級(jí)聯(lián)選擇器數(shù)據(jù)回顯問題
對(duì)于前端小菜雞來說,被這個(gè)問題也是困擾了好久。也是百度的方法。
表單部分代碼:
<el-form-item label="部門名稱:" prop="deptId"> <el-cascader placeholder="請(qǐng)選擇部門" :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) //數(shù)據(jù)雙向綁定 }, changeDetSelect(key,treeData){ let arr = []; // 在遞歸時(shí)操作的數(shù)組 let returnArr = []; // 存放結(jié)果的數(shù)組 let depth = 0; // 定義全局層級(jí) // 定義遞歸函數(shù) function childrenEach(childrenData, depthN) { for (var j = 0; j < childrenData.length; j++) { depth = depthN; // 將執(zhí)行的層級(jí)賦值 到 全局層級(jí) arr[depthN] = (childrenData[j].id); if (childrenData[j].id == key) { returnArr = arr.slice(0, depthN+1); //將目前匹配的數(shù)組,截?cái)嗖⒈4娴浇Y(jié)果數(shù)組, break } else { if (childrenData[j].nodes) { depth ++; childrenEach(childrenData[j].nodes, depth); } } } return returnArr; } return childrenEach(treeData, depth); },
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue使用vue-cli創(chuàng)建項(xiàng)目
這篇文章主要介紹了Vue使用vue-cli創(chuàng)建項(xiàng)目,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-09-09vue制作點(diǎn)擊切換圖片效果的詳細(xì)思路與步驟
這篇文章主要給大家介紹了關(guān)于vue制作點(diǎn)擊切換圖片效果的詳細(xì)思路與步驟,圖片切換是一個(gè)很經(jīng)典的Vue入門學(xué)習(xí)案例,在你學(xué)習(xí)完一些基本的v-指令后,你可以嘗試去寫一個(gè)簡(jiǎn)單的demo去鞏固和熟悉這些指令的使用方法,需要的朋友可以參考下2023-11-11