[英]Pass extra parameters to custom sort function in AngularJS
這是我的代碼
<a href="" ng-click="predicate = 'productname'; reverse=false">Productname</a>
<a href="" ng-click="predicate = 'productprice'; reverse=false">Productprice</a>
迭代
<div ng-repeat="sale in sales | orderBy:customSort">
海關功能
$scope.customSort = function(sale) {
};
目前在customSort函數中,我得到了所有的銷售數據,但我也希望將謂詞值傳遞給函數,以便它可以進行相應的排序(如果點擊名稱,則按名稱排序,如果單擊價格謂詞,則按價格排序。)
如何將謂詞值傳遞給customSort函數?任何人都可以幫我這個嗎? 謝謝。
您可以使用謂詞調用自定義排序並返回一個閉包作為原始函數,現在您的函數可以訪問謂詞:
<div ng-repeat="sale in sales | orderBy:customSort(predicate)">
$scope.customSort = function(predicate) {
return function(sale) {
};
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.