我有一个ng-repeat
,在下拉列表中有以下值。
Up to 6 months
From 13 to 24 months
Higher than 24 months
From 6 to 12 months
我需要对值进行排序,如下所示
//following is the expected output
// Up to 6 months
//From 6 to 12 months
//From 13 to 24 months
//Higher than 24 months
$scope.items = [{name: 'Up to 6 months', id: 30 },{ name: 'From 13 to 24 months', id: 27 },{ name: 'Higher than 24 months', id: 50 },{ name: 'From 6 to 12 months', id: 50 }];
答案 0 :(得分:1)
答案 1 :(得分:0)
您的商品将按此加载
$scope.selectedItem = { name: 'two', id: 27 };
$scope.items = [{name: 'Up to 6 months',sort:1, id: 30 },{ name: 'From 13 to 24 months',sort:3, id: 27 },{ name: 'Higher than 24 months',sort:4, id: 50 },{ name: 'From 6 to 12 months', sort:2, id: 50 }];
纳克重复
<select ng-model="selectedItem">
<option ng-repeat="item in items | orderBy:['sort']" value={{item.id}}>
{{item.name}}
</option>
</select>