我在angularjs中有一些表格數據,我正在用標準排序函數排序。我想知道如何獲取包含特定值的表的行,以便首先顯示。AngularJS Orderby
Item Category1 Category2
的Item
領域始終是唯一的,但也有對Category1
相同值的多個項目。
有沒有一種方法可以使用自定義的orderBy
函數獲取具有某個Category1
值的所有項目,以便首先顯示出來?
我在angularjs中有一些表格數據,我正在用標準排序函數排序。我想知道如何獲取包含特定值的表的行,以便首先顯示。AngularJS Orderby
Item Category1 Category2
的Item
領域始終是唯一的,但也有對Category1
相同值的多個項目。
有沒有一種方法可以使用自定義的orderBy
函數獲取具有某個Category1
值的所有項目,以便首先顯示出來?
要列出一個特定值的所有條目第一,只爲您在您的排序函數值,並返回一個較低的數字與該值的項目比其他項目。例如。
$scope.showValueFirst = function(item) {
return item.Category1 == 'matched value' ? 0 : 1;
}
ngRepeat="item in items | orderBy:sortByCategory"
你可以寫這樣一個功能:
$scope.sortByCategory = function(item){
return (item.category1 < item.category2);
}
不應該是'$ scope.sortByCategory = function(item)...'? –
[orderBy filter's](https://docs.angularjs.org/api/ng/filter/orderBy)表達式可以是一個函數。 –