使用 Element UI 的 el-table 組件進(jìn)行樹形層級(jí)的金額匯總_第1頁(yè)
使用 Element UI 的 el-table 組件進(jìn)行樹形層級(jí)的金額匯總_第2頁(yè)
使用 Element UI 的 el-table 組件進(jìn)行樹形層級(jí)的金額匯總_第3頁(yè)
使用 Element UI 的 el-table 組件進(jìn)行樹形層級(jí)的金額匯總_第4頁(yè)
使用 Element UI 的 el-table 組件進(jìn)行樹形層級(jí)的金額匯總_第5頁(yè)
全文預(yù)覽已結(jié)束

下載本文檔

版權(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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論