json数组某个数值对应渲染

当你统计某一年的某个值它对应的月份总数时,后台没有直接处理好,某个月对应某个值,这样会增加统计的负担,但当数据时这样的时候,在angularjs中时不能直接引用的。

"data":[

{"type":"无敌停车场","count":[0,3,0,0,0,0,0,0,0,0,0,0]},
{"type":"冰天雪地","count"
:[0,2,0,0,0,0,0,0,0,0,0,0]},
{"type":"上川停车场","count":[0,8,0,0,0,0,0,0,0,0,0,0]}]

页面显示我想展示这样的
angularjs中无法用repeat来遍历数组。所以必须要用for来循环遍历这个json数组中的count的值。

页面代码:
<table class="table table-bordered table-hover table-striped" style="padding-left: 0;"  id="totalMonth">
    <thead>
    <tr>
        <th colspan="13" style="font-size: large;color: #3b98d6">
           统计某个停车场App的使用量
        </th>
    </tr>
    <tr>
        <th>停车场名称</th>
        <th>1月</th>
        <th>2月</th>
        <th>3月</th>
        <th>4月</th>
        <th>5月</th>
        <th>6月</th>
        <th>7月</th>
        <th>8月</th>
        <th>9月</th>
        <th>10月</th>
        <th>11月</th>
        <th>12月</th>
    </tr>
    </thead>
    <tbody id="countName" colspan="13"></tbody>
</table>

js
for(var i = 0;i< data.data.length;i++){
    content +='<tr><td>'+data.data[i].type+'</td>';
    for(var j=0;j<data.data[i].count.length;j++){
        content+='<td>'+data.data[i].count[j]+'</td>';
    }
    content +='</tr>';
    $('#countName').html(content);  //将content数据渲染到id为countName
}

 




 
 
posted @ 2017-02-23 17:02  liziyou  阅读(1021)  评论(0编辑  收藏  举报