




下載本文檔
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
使用ElementUI的el-table組件進(jìn)行樹形層級(jí)的
金額匯總在使用ElementUI的el-table組件進(jìn)行樹形層級(jí)的金額匯總時(shí),你可以通過(guò)以下步驟來(lái)實(shí)現(xiàn):確保你的數(shù)據(jù)源是層級(jí)結(jié)構(gòu)的樹形數(shù)據(jù),并在el-table中使用tree-props配置項(xiàng)指定樹形數(shù)據(jù)的屬性字段名。例如,使用tree-props=”{children:'children;hasChildren:'hasChildren'}"來(lái)指定子節(jié)點(diǎn)數(shù)組的字段名為'children',以及是否有子節(jié)點(diǎn)的字段名為'hasChildren'o在表格的columns配置中,添加一個(gè)需要進(jìn)行金額匯總的列,設(shè)置column-key屬性值為該列對(duì)應(yīng)的數(shù)據(jù)字段。例如,column-key="amount"o在表格的最底部或其他需要展示匯總結(jié)果的位置,使用計(jì)算屬性(computed)計(jì)算樹形結(jié)構(gòu)下的金額匯總。在計(jì)算屬性中,可以使用遞歸遍歷樹形數(shù)據(jù),累加相關(guān)金額字段的值。在el-table中,使用scoped-slot的方式自定義某一列的顯示內(nèi)容。你可以在scopedslot內(nèi)部訪問(wèn)到每一行的數(shù)據(jù),然后根據(jù)需求進(jìn)行展示。在金額匯總的計(jì)算屬性中,將計(jì)算結(jié)果綁定到scoped-slot中展示即可。以下是一個(gè)示例代碼,演示了在el-table中實(shí)現(xiàn)樹形層級(jí)的金額匯總:〈template)<el-table:data=*treeData":tree-props="{children:'children',hasChildren:'hasChildren'}“〉<el-table-columnprop=*najne*label="名稱"X/el-table-column〉<el-table-coluninprop="amount"label="金額"colujm-key="amount”〉〈templateslot-scope=*{row/〉{{row.amount}}〈/template〉</el-table-colu?n></el-table><div>匯總金額:HtotalAmount}}</div>〈/template〉〈script)exportdefault{data(){return(treeData:[(name:'節(jié)點(diǎn)1',amount:100,hasChildren:true,children:[{name:'節(jié)點(diǎn)1.1',amount:50,hasChildren:false},{name:'節(jié)點(diǎn)1.2',amount:30,hasChildren:false}]name:'節(jié)點(diǎn)2',amount:70,hasChildren:true,children:[{name:'節(jié)點(diǎn)2.1',amount:40,hasChildren:false),{name:'節(jié)點(diǎn)2.2',amount:20,hasChildren:false}]}]}:},computed:{totalAnount(){returnthis,calculateTotalAmount(this.treeData):)1,methods:{calculateTotalAmount(data){lettotal=0;data.forEach((item)=>{total+=item,amount;if(item,children&&item.children,length>0){total+=this.calculateTotalAmount(item,children);}});returntotal;};〈/script)<template><el-table:data="treeData":tree-props="{children:'children',hasChildren:'hasChildren'}"><el-table-columnprop="name"label="名稱"></el-table-column><el-table-columnprop="amount"label="^^"column-key="amount"><templateslot-scope="{row}">{{row.amount}}</template></el-table-column></el-table><div>匯總金額:{{totalAmount)}</div></template><script>exportdefault{data(){return{treeData:[(name:'節(jié)點(diǎn)1',amount:100,hasChildren:true,children:[{name:'節(jié)點(diǎn)1.1',amount:50,hasChildren:false},{name:節(jié)點(diǎn)12,amount:30,hasChildren:false)]},|name:'節(jié)點(diǎn)2\amount:70,hasChildren:true,children:[{name:,節(jié)點(diǎn)2.1',amount:40,hasChildren:false},(name:'節(jié)點(diǎn)22,amount:20,hasChildren:false)])]);},computed:{totalAmount(){returnthis.calculateTotalAmount(this.treeData);)},methods:{calculateTotalAmount(data){lettotal=0;data.forEach((item)=>{total+=item.amount;if(item.children&&item.children.length>0){total+=this.calculateTotalAmount(item.children);)));returntotal;)));</script>在上面的示例中,我們定義了一個(gè)名為treeData的data屬性來(lái)存儲(chǔ)樹形結(jié)構(gòu)的數(shù)據(jù)。通過(guò)el-table的tree-props屬性配置,我們將'children'和,hasChildrerV字段與樹
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年中國(guó)混凝土預(yù)制樁行業(yè)發(fā)展前景及投資戰(zhàn)略咨詢報(bào)告
- 排水防澇設(shè)施功能提升項(xiàng)目實(shí)施范圍與內(nèi)容
- 供熱管網(wǎng)及供熱設(shè)施提升改造技術(shù)路線與工藝選擇
- 中國(guó)月見草油市場(chǎng)發(fā)展前景預(yù)測(cè)及投資戰(zhàn)略研究報(bào)告
- 零碳數(shù)據(jù)算力中心項(xiàng)目可行性研究報(bào)告
- 抗裂砂漿合同范本
- 一次函數(shù)與一元一次不等式(基礎(chǔ))知識(shí)講解
- 牛肝菌買賣合同范本
- 2025年床式振動(dòng)干燥機(jī)項(xiàng)目投資可行性研究分析報(bào)告
- 河南醫(yī)藥制造業(yè)市場(chǎng)前景及投資研究報(bào)告
- 大數(shù)據(jù)與能源經(jīng)濟(jì)分析
- 小班數(shù)學(xué)課件《認(rèn)識(shí)長(zhǎng)方形》
- 淺談第三方物流的倉(cāng)儲(chǔ)管理
- 21ZJ111 變形縫建筑構(gòu)造
- 醫(yī)院各委員會(huì)職責(zé)制度
- 心理健康與職業(yè)生涯(中職)PPT完整全套教學(xué)課件
- 改良經(jīng)皮經(jīng)肝膽道鏡術(shù)New
- 2萬(wàn)噸馬鈴薯深加工(淀粉)項(xiàng)目可行性研究報(bào)告
- 服飾品設(shè)計(jì)PPT完整全套教學(xué)課件
- 顱腦橫斷層解剖09課件
- 2023年同等學(xué)力申碩英語(yǔ)真題
評(píng)論
0/150
提交評(píng)論