我想创建一个HTML表格,该表格使用控制器中的(动态)列模型来呈现对象属性,具体取决于此列模型。我需要能够更改在控制器中定义的表列的顺序。
这是一个例子:
myapp.controller('controller', function ($scope, $http) {
// List of objects
$scope.list = [
{ a : 1, b : 2, c : 3},
{ a : 2, b : 3, c : 4},
{ a : 3, b : 4, c : 5}
];
// Properties to be displayed
$scope.fields = [ "c", "b", "a" ];
});`
模板:
<table>
<tr ng:repeat="item in list">
<td ng:repeat="field in fields">
{{item.<field>}}
</td>
</tr>
</table>
所以,项目。应该是类似于item。[a | b | c]之类的东西,以通过属性a,b或c呈现值。但是我不知道如何使这种情况正常工作。
因为我对angular还是很陌生,所以我不确定这是否是一个好方法,或者是否有其他不错的解决方案来渲染这样的东西。
<table>
<tr ng:repeat="item in list">
<td ng:repeat="field in fields">
{{ item[field] }}
</td>
</tr>
</table>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句