I have an array like-:
aw_score_list = {
'6':99,'5.5':98,'5':93,'4.5':80,'4':56,'3.5':38,'3':15,'2.5':7,'2':2,'1.5':1,'1':1,
};
我想将这个内容转换成HTML表格,使其变成像这样。
keys Values
6 99
5.5 98
请告诉我如何设置一个for循环
I have an array like-:
aw_score_list = {
'6':99,'5.5':98,'5':93,'4.5':80,'4':56,'3.5':38,'3':15,'2.5':7,'2':2,'1.5':1,'1':1,
};
keys Values
6 99
5.5 98
请告诉我如何设置一个for循环
请参阅ngRepeat-迭代对象属性。
假设您的数组在模板中的作用域内...
<table>
<thead>
<tr>
<th>keys</th>
<th>Values</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="(key, val) in aw_score_list">
<td>{{key}}</td>
<td>{{val}}</td>
</tr>
</tbody>
</table>
$scope.aw_score_list = {...}
的东西。 - Philaw_score_list_preserve_order = [
{key:'6' , value:99},
{key:'5.5' , value:98},
{key:'5' , value:93},
{key:'4.5' , value:80},
{key:'4' , value:56},
{key:'3.5' , value:38},
{key:'3' , value:15},
{key:'2.5' , value:7},
{key:'2' , value:2},
{key:'1.5' , value:1},
{key:'1' , value:1},
]
<div ng-repeat="item in aw_score_list_preserve_order | orderBy:key:true">...</div>
,如果您想要升序排列,请删除 :true
部分,并查看 orderBy 的文档。 - rabbit.aaron