Js foreach用于创建桌面

时间:2016-04-12 05:13:43

标签: javascript foreach

我正在使用下面的代码动态创建表标题。

var tableHeaders = "<th>No</th>";
            tableHeaders += "<th>Devices</th>";
            tableHeaders += "<th>Users</th>";
    response.forEach(function(entry){ 
                            entry.chartElements.forEach(function(childrenEntry) {
                              tableHeaders += "<th>" + childrenEntry.label + "</th>";
                            });
                        });

只有foreach之外的 tableHeaders 正在运行,它不会在foreach中附加 标记。我在这里做错了什么。!!!!

服务器响应

0: Object
      chartElements: [{count: 1
                     label: "Lollipop"
                     totalCount: 0}]
      deviceCount: 1
      deviceName: "Lenovo"

1: Object
    chartElements: [{count: 1
                     label: "Lollipop"
                     totalCount: 0}]
      deviceCount: 1
      deviceName: "Zenfone"
2: Object
    chartElements: [{count: 1
                     label: "Lollipop"
                     totalCount: 0}]
      deviceCount: 1
      deviceName: "MotoG"
3: Object
    chartElements: [{count: 1
                     label: "Lollipop"
                     totalCount: 0}]
      deviceCount: 1
      deviceName: "Nexus5

0 个答案:

没有答案