首页 > 编程语言 > 详细

json数组某个数值对应渲染

时间:2017-02-23 17:28:43      阅读:203      评论:0      收藏:0      [点我收藏+]

当你统计某一年的某个值它对应的月份总数时,后台没有直接处理好,某个月对应某个值,这样会增加统计的负担,但当数据时这样的时候,在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
}



 
 

json数组某个数值对应渲染

原文:http://www.cnblogs.com/liziyou/p/6434366.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!