我有一个对象列表,如下所示
{
"Info":[
{
"Id":1,
"shortId":"PH",
"description":"Phone"
},
{
"Id":2,
"shortId":"Email",
"description":"Email"
},
{
"Id":3,
"shortId":"M-AD",
"description":"Mailing Address"
},
{
"Id":4,
"shortId":"B-AD",
"description":"Billing Address"
},
{
"Id":5,
"shortId":"OTH",
"description":"Other"
}
]
}
我按ID排序并在UI上显示。但现在订购应该是
{
"Info":[
{
"Id":2,
"shortId":"Email",
"description":"Email"
},
{
"Id":1,
"shortId":"PH",
"description":"Phone"
},
{
"Id":4,
"shortId":"B-AD",
"description":"Billing Address"
},
{
"Id":3,
"shortId":"M-AD",
"description":"Mailing Address"
},
{
"Id":5,
"shortId":"OTH",
"description":"Other"
}
]
}
我试过地图但没有工作。在Angularjs还有其他方法吗?
答案 0 :(得分:0)
试试这个:
$scope.yourObject = $filter('orderBy')($scope.yourObject, 'id');
或在你的html中:
<ul>
<li ng-repeat="x in yourObject | orderBy:'id'">{{x}}</li>
</ul>