簡體   English   中英

通過dom-repeat打印DOM數組

[英]printing the DOM array through dom-repeat

我有一個Array graphData 現在,我想使用dom-repeat進行打印。

<template is='dom-repeat' items='{{internalgraphData}}'>
                        <tr>
                            <td>{{item.asset}}</td>
                            <td>{{item.percentage}}%</td>
                            <td>{{item.investment}}</td>
                            <td>{{item.currentvalue}}</td>
                            <td class="u-value-align"><span class="red-text darken-4">{{item.gain}}</span></td>
                            <td><img src="../images/arrow-red.png"></td>
                            <td class="black-text"><a class="waves-effect waves-light btn white blue-text back" href="equity.html">Select</a></td>
                        </tr>
                    </template>

我的json如下所示:我嘗試使用下面的標簽值“ internalgraphData”創建dom-repeat結構,並打印了internalgraphData,看起來我已成功將數據從json傳輸到了本地標簽值結構“ internalgraphData”

 Polymer({  is: 'my-menu',
........
ready : function(graphid,graphData) {
                            this.graphData = [
                                ['Equity', 50,25000,37000,240],
                                ['Bonds', 35,12500,10000,-480],
                                ['Alternates',5, 2000,2000,340],
                                ['Cash',10,1000,1000,-140]
                            ];

                            if (this.graphData.length > 0)
                            {
                                for(i = 0; i< this.graphData.length; i++)
                                {
                                    this.internalgraphData.push({
                                        "asset" : this.graphData[i][0],
                                        "percentage" : this.graphData[i][1],
                                        "investment" : this.graphData[i][2],
                                        "currentvalue" : this.graphData[i][3],
                                        "gain" : this.graphData[i][4]

                                    }); 
                                }

但是我看到dom-repeat不能打印。 誰能幫助我們實現這一目標?

注意:如果我顯式添加標記值...表將要出現...

this.internalgraphData = [
                        /*['Equity', 50,25000,37000,240],
                        ['Bonds', 35,12500,10000,-480],
                        ['Alternates',5, 2000,2000,340],
                        ['Cash',10,1000,1000,-140]*/

                        {asset: 'Equity', percentage: 50, investment: 25000, currentvalue: 37000, gain: 240 },
                        {asset: 'Equity', percentage: 35, investment: 12500, currentvalue: 10000, gain: -480 },
                        {asset: 'Equity', percentage: 5,  investment: 2000, currentvalue: 2000, gain: 340 },
                        {asset: 'Equity', percentage: 10, investment: 1000, currentvalue: 1000, gain: -140 }
                    ];
this.internalgraphData.push({});

上面的循環操作不能反映聚合物數據的變化。下面是推薦的數組對象的方法。

this.push('internalgraphData', {title:'hey'}); 如果您不能這樣做。 請按以下方式使用

this.updatedgraphData  = JSON.parse(JSON.stringify(this.internalgraphData ));

***updatedgraphData***使用dom-repeat

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM