Liakat Liakat - 4 months ago 28
Node.js Question

printing the DOM array through dom-repeat

I have one Array graphData. Now I want to use dom-repeat to print it.

<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>


My json is as below... I tried to create the dom-repeat structure with below tag-value "internalgraphData"
I printed internalgraphData, it looks I successfully transferred the data from json to local tag-value structure "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]

});
}


But I see that the dom-repeat is not printing .
Could anyone help how can we achieve that?

NOTE: If I add the tag-value explicitly... the table is coming...

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 }
];

Answer
this.internalgraphData.push({});

above operations in loop doesn't reflect in polymer data-change.Below is the recommended way to object in array.

this.push('internalgraphData', {title:'hey'}); if you can't do this way. please use below way

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

use dom-repeat over ***updatedgraphData***

Comments