小編給大家分享一下knockoutjs模板如何實(shí)現(xiàn)樹形結(jié)構(gòu)列表,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
吳忠網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,吳忠網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為吳忠成百上千提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢,請找那個售后服務(wù)好的吳忠做網(wǎng)站的公司定做!
數(shù)據(jù)結(jié)構(gòu)
/*數(shù)據(jù)*/ var ko_vue_data=[ { name: "總能耗", number:"0", energyone: 14410, energytwo: 1230, energythree: 1230, huanRatio: -36.8, tongRatio: 148.5, child: [ { name: "租戶電耗", number:"1", energyone: 14410, energytwo: 1230, energythree: 1230, huanRatio: -36.8, tongRatio: 148.5, child: [] }, { name: "公共用電", number:"2", energyone: 14410, energytwo: 1230, energythree: 1230, huanRatio: -36.8, tongRatio: 148.5, child: [ { name: "暖通空調(diào)", number:"2.1", energyone: 14410, energytwo: 1230, energythree: 1230, huanRatio: -36.8, tongRatio: 148.5, child: [ { name: "冷站", number:"2.1.1", energyone: 14410, energytwo: 1230, energythree: 1230, huanRatio: -36.8, tongRatio: 148.5, child: [ { name: "冷水機(jī)組", number:"2.1.1.1", energyone: 14410, energytwo: 1230, energythree: 1230, huanRatio: -36.8, tongRatio: 148.5, child: [] } ] }, { name: "熱力站", number: "2.1.2", energyone: 14410, energytwo: 1230, energythree: 1230, huanRatio: -36.8, tongRatio: 148.5, child: [] } ] } ] } ] } ];
效果圖
之前已經(jīng)寫過用Vue實(shí)現(xiàn)圖上效果的方法,此篇為用knockout.js實(shí)現(xiàn)上圖效果的方法,同樣通過模板將數(shù)據(jù)綁定到頁面。
模板代碼
請對比之前一篇Vue的方法,了解兩種方式模板綁定方式的不同。
模板寫完,在頁面上使用模板。
html代碼
JavaScript代碼
/*數(shù)據(jù)*/ var ko_vue_data=[ { name: "總能耗", number:"0", energyone: 14410, energytwo: 1230, energythree: 1230, huanRatio: -36.8, tongRatio: 148.5, child: [ { name: "租戶電耗", number:"1", energyone: 14410, energytwo: 1230, energythree: 1230, huanRatio: -36.8, tongRatio: 148.5, child: [] }, { name: "公共用電", number:"2", energyone: 14410, energytwo: 1230, energythree: 1230, huanRatio: -36.8, tongRatio: 148.5, child: [ { name: "暖通空調(diào)", number:"2.1", energyone: 14410, energytwo: 1230, energythree: 1230, huanRatio: -36.8, tongRatio: 148.5, child: [ { name: "冷站", number:"2.1.1", energyone: 14410, energytwo: 1230, energythree: 1230, huanRatio: -36.8, tongRatio: 148.5, child: [ { name: "冷水機(jī)組", number:"2.1.1.1", energyone: 14410, energytwo: 1230, energythree: 1230, huanRatio: -36.8, tongRatio: 148.5, child: [] } ] }, { name: "熱力站", number: "2.1.2", energyone: 14410, energytwo: 1230, energythree: 1230, huanRatio: -36.8, tongRatio: 148.5, child: [] } ] } ] } ] } ]; function addAttribute(dst){ for(var i=0;icss樣式同之前一篇Vue的一致,在這里就不在贅述,如有需要可查看之前一篇。到此兩種方式算是全部寫完,在報(bào)表多的頁面,對于以上代碼,稍加修改即可復(fù)用,綁定數(shù)據(jù)非常方便。
以上是“knockoutjs模板如何實(shí)現(xiàn)樹形結(jié)構(gòu)列表”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
網(wǎng)頁名稱:knockoutjs模板如何實(shí)現(xiàn)樹形結(jié)構(gòu)列表
文章分享:http://weahome.cn/article/gegcid.html