说我在ng-repeat
中有4个项目。如何在orderBy
中排除一个项目?
<li ng-repeat="item in items | orderBy:'id':true">
$scope.items = [
{"name":"item1","id":1},
{"name":"item2","id":2},
{"name":"item3","id":3},
{"name":"item4","id":4}
];
我怎样才能说id:3总是作为第一项出现?
答案 0 :(得分:9)
您可以创建一个函数来更改按(plunker)排序的值:
$scope.itemSortValue = function(item) {
if (item.id == 3)
return -1;
return item.id;
}
HTML:
<li ng-repeat="item in items | orderBy:itemSortValue">
{{item.name}}
</li>