我有一个数组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({});
循环中的上述操作不会反射(reflect)在 polymer 数据更改中。下面是在数组中对象的推荐方法。
this.push('internalgraphData', {title:'hey'});
如果你不能这样做。请使用以下方式
this.updatedgraphData = JSON.parse(JSON.stringify(this.internalgraphData ));
在 ***updatedgraphData***
上使用 dom-repeat
关于javascript - 通过 dom-repeat 打印 DOM 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38765558/