请检查这个小提琴: http://jsfiddle.net/houmaka/vHXy4/
当用户填写不同的字段时,重复排序输出。如何根据我的字段数组强制执行自定义排序? (表格中有超过20个字段,我只是提供了实际表格的快照。)
快速浏览一下:$scope.fields = [];
$scope.fields = {
contact_person: 'Contact Person',
app_owner_name: 'Name of Application Owner',
app_owner_phone_number: 'Application Owner Phone Number',
}
并向他们展示:
<div>
<div ng-repeat="(key, value) in user">
<div ng-show="value">
<div>{{fields[key]}}:</div>
<div>{{value}}</div>
</div>
</div>
</div>
由于
答案 0 :(得分:1)
我建议这个字段模型:
$scope.fields = [
{ index: 3, name: 'Contact Person', id: 'contact_person' },
{ index: 2, name: 'Name of Application Owner', id: 'app_owner_name' },
{ index: 1, name: 'Application Owner Phone Number', id: 'app_owner_phone_number' },
];
这个ngRepeat用法:
<div ng-repeat="field in fields | orderBy: 'index' ">
<div ng-show="user[field.id]">
<div>{{field.name}}</div>
<div>{{user[field.id]}}</div>
</div>
</div>