2013-11-04 75 views
0
排序

可能是一個非常不好的問題,我很明顯失蹤,但我使用的是一個函數來排序我的結果。 每個結果都有一個價格和一個權重(基本優先)角度多種排序,按

我想結果按價格排序,但有相同的價格結果,他們需要按重量排序。我也可以逆轉排序,所以低 - 高/高 - 低。

下面是一些諾迪數據

http://plnkr.co/edit/VH2WvyJMsLSTpWJawT2f?p=preview

在應用的過程中plunker(我有上百個結果),我用這個

$scope.orderByFunction = function (result) { 
    if ($scope.orderBy == 'price-low-high') { 
     return result.totalPrice.amount + result.boost; 
    } 
    if ($scope.orderBy == 'price-high-low') { 
     return -result.totalPrice.amount + result.boost; 
    } 
    else return result.totalPrice.amount + result.boost; 
}; 

雖然我認爲這是最初的成功,它出現了一些錯誤,因爲它顯示價格更高的價格高於低價位的結果。欣賞它的我很難證明,所以我想我會問諾迪問題第一:)

鉭 湯姆

+1

我想它有點...不看到不規則的排序 – charlietfl

+0

現在看。我已經添加了更多結果並使用了上面的訂購代碼 http://plnkr.co/edit/VH2WvyJMsLSTpWJawT2f?p=preview Price 150 shows above price 100.猜測這是我的一些非常愚蠢的錯誤。 – Leads

+0

建議您縮小重複elemnt尺寸'H1'?並給人們複製的步驟...我只是沒有看到它 – charlietfl

回答

0

https://groups.google.com/forum/#!topic/angular/XAJ2hyeRSTU

這回答了是HTML http://plnkr.co/edit/VH2WvyJMsLSTpWJawT2f?p=preview 排序依據:[orderByPrice ,orderByPriority]

和JS

$scope.orderByPrice = function (result) { 
    if ($scope.orderBy == 'price-low-high') { 
     return result.amount; 
    } 
    if ($scope.orderBy == 'price-high-low') { 
     return -result.amount; 
    } 
    else return result.totalPrice.amount; 
}; 
$scope.orderByPriority = function (result) { 
     return result.priority; 
};