首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过DOM -重复打印dom数组

通过DOM -重复打印dom数组
EN

Stack Overflow用户
提问于 2016-08-04 11:02:22
回答 1查看 68关注 0票数 0

我有一个数组graphData。现在我想用dom-重复打印它。

代码语言:javascript
复制
<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>

我的儿子如下..。我尝试用下面的标签值"internalgraphData“创建dom-重复结构,我打印了internalgraphData,看起来我成功地将数据从json传输到本地标记值结构"internalgraphData”。

代码语言:javascript
复制
 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]

                                    }); 
                                }

但我看到,重复并不是打印。谁能帮上忙,我们怎么做到呢?

注意:如果我显式地添加标记值.桌子来了..。

代码语言:javascript
复制
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 }
                    ];
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-04 11:30:05

代码语言:javascript
复制
this.internalgraphData.push({});

以上循环操作不反映聚合物数据的变化,下面是阵列对象的推荐方法。

如果你不能这样做的话,this.push('internalgraphData', {title:'hey'});。请用下面的方式

代码语言:javascript
复制
this.updatedgraphData  = JSON.parse(JSON.stringify(this.internalgraphData ));

***updatedgraphData***上使用dom-重复

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38765558

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档