使用table做成樹(shù)形結(jié)構(gòu)的table
更新時(shí)間:2024年07月25日 10:20:42 作者:愛(ài)跳舞的程序員
這篇文章主要介紹了使用table做成樹(shù)形結(jié)構(gòu)的table問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
table做成樹(shù)形結(jié)構(gòu)的table
<el-table :default-expand-all="false" :data="list" style="width: 100%; margin-bottom: 20px" row-key="listId" border :tree-props="{ children: 'children', hasChildren: 'hasChildren' }" lazy :load="load" > <el-table-column prop="bppjName" label="部件名稱"> </el-table-column> <el-table-column prop="stkName" label="物資名稱"> </el-table-column> <el-table-column prop="stkCode1" label="物資編碼"> </el-table-column> <el-table-column prop="stkCode" label="型號(hào)規(guī)格"> </el-table-column> <el-table-column prop="metric" label="單位" width="80" align="center"> </el-table-column> <el-table-column prop="num" label="數(shù)量" width="80" align="center"> </el-table-column> <el-table-column prop="note" label="備注"> </el-table-column> </el-table>
getList() { // 一開(kāi)始獲取數(shù)據(jù)列表 const obj = { listId: this.listId, }; getList(obj).then((res) => { this.list = res.rows; this.list.forEach((item) => { // 必須要設(shè)置,不然沒(méi)有下級(jí)圖標(biāo)顯示 item.hasChildren = true; item.children = null; }); }); }, load(tree, treeNode, resolve) { // 獲取下一個(gè)節(jié)點(diǎn)數(shù)據(jù) 手動(dòng)添加上給當(dāng)前的節(jié)點(diǎn) getUdmBppjDataList({ listId: tree.listId }).then((res) => { const childList = res.rows; childList.forEach((item) => { // 必須要設(shè)置,不然沒(méi)有下級(jí)圖標(biāo)顯示 item.hasChildren = true, item.children = null; }); setTimeout(() => { resolve(childList); }, 500); }); },
table樹(shù)形結(jié)構(gòu),獲取一個(gè)節(jié)點(diǎn)的所有父節(jié)點(diǎn)
數(shù)據(jù)
let tree = [ { id:1, code: '1', fsecid:0, children: [ { id:11, fsecid:1, code:'1.1', children: [ { id:111, fsecid:11, code: '1.1.1', } ] }, { id:12, fsecid:1, code: '1.2', } ] }, { code: '2', id:2, fsecid:0, children: [ { id:21, fsecid:2, code: '2.1', } ] } ] let result=scheduleAlgorithm(tree,11,'fsecid','children') console.log("result=====",result); //結(jié)果 result===== [ 1, 11 ]
標(biāo)題函數(shù)實(shí)現(xiàn)
/**判斷葉子節(jié)點(diǎn)的所有父節(jié)點(diǎn)*/ function scheduleAlgorithm( array,//樹(shù)形數(shù)據(jù) value,//找到valueName屬性名 所等于這個(gè)值所有的父節(jié)點(diǎn),2,3參數(shù)是關(guān)聯(lián)的 valueName = "fsecid",//與上一節(jié)點(diǎn)相關(guān)聯(lián)的值的字段名,當(dāng)前節(jié)點(diǎn)的父節(jié)點(diǎn)id childrenName = "children",//存放子節(jié)點(diǎn)數(shù)據(jù)的數(shù)組名稱 ) { if (!value || !Array.isArray(array)) return []; const result = []; let valid = false; const seek = (array, value) => { let parentValue = ""; const up = (array, value, lastValue) => { array.forEach(v => { const val = v[valueName]; const child = v[childrenName]; if (val === value) { valid = true; parentValue = lastValue; return; } if (child && child.length) up(child, value, val); }); }; up(array, value); if (parentValue) { result.unshift(parentValue); seek(array, parentValue); } }; seek(array, value); return valid ? [...result, value] : []; }
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue使用vue-cli創(chuàng)建項(xiàng)目
這篇文章主要介紹了Vue使用vue-cli創(chuàng)建項(xiàng)目,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09vue總線機(jī)制(bus)知識(shí)點(diǎn)詳解
在本篇文章中小編給大家整理的是關(guān)于vue總線機(jī)制(bus)知識(shí)點(diǎn)總結(jié),有興趣的朋友們可以跟著學(xué)習(xí)下。2020-05-05vue+vue-router轉(zhuǎn)場(chǎng)動(dòng)畫(huà)的實(shí)例代碼
今天小編就為大家分享一篇vue+vue-router轉(zhuǎn)場(chǎng)動(dòng)畫(huà)的實(shí)例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-09-09vue+element 模態(tài)框表格形式的可編輯表單實(shí)現(xiàn)
這篇文章主要介紹了vue+element 模態(tài)框表格形式的可編輯表單實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-06-06使用vue-cli搭建SPA項(xiàng)目的詳細(xì)過(guò)程
vue-cli是vue.js的腳手架,用于自動(dòng)生成vue.js+webpack的項(xiàng)目模板,本文通過(guò)實(shí)例代碼給大家介紹vue-cli搭建SPA項(xiàng)目的詳細(xì)過(guò)程,感興趣的朋友跟隨小編一起看看吧2022-09-09Vue中實(shí)現(xiàn)動(dòng)態(tài)右鍵菜單的示例代碼
在前端開(kāi)發(fā)中,實(shí)現(xiàn)自定義右鍵菜單能夠?yàn)橛脩籼峁└喙δ苓x項(xiàng),本文就來(lái)介紹了Vue中實(shí)現(xiàn)動(dòng)態(tài)右鍵菜單的示例代碼,感興趣的可以了解一下2024-11-11npm?ERR!?code?E404在vscode安裝插件時(shí)報(bào)錯(cuò)的兩種解決方案
這篇文章主要給大家介紹了關(guān)于npm?ERR!?code?E404在vscode安裝插件時(shí)報(bào)錯(cuò)的兩種解決方案,關(guān)于這個(gè)問(wèn)題,通常是由于插件名稱輸入錯(cuò)誤、網(wǎng)絡(luò)問(wèn)題或插件已被刪除引起的,文中將兩種解決方法都介紹的非常詳細(xì),需要的朋友可以參考下2023-04-04