Wie kann ich eine Methode mit orderBy verwenden?Methode mit orderBy in ng-repeat verwenden
Ich möchte meine Array von ng-repeat sortieren mit einem Verfahren und nicht eine Eigenschaft:
index.html
<tbody>
<tr ng-repeat="product in results.data | orderBy: product.getAllCounter()">
<!-- Product name -->
<td ng-bind="(product.product_offer[0].app_name === null) ? product.app.store_id : product.product_offer[0].app_name"></td>
<!-- Counter -->
<td class="text-right" ng-bind="product.getAllCounter()"></td>
<!-- Action -->
<td class="text-center">
<div class="btn-group">
<a ng-href="/#/product/{{ product.id }}" type="button" class="btn btn-default btn-sm">
See
</a>
</div>
</td>
</tr>
</tbody>
Product.prototype.getAllCounter
// Return result all counter in promo
Product.prototype.getAllCounter = function() {
var sum = 0;
angular.forEach(this.product_promo_linker, function (product_promo_linker) {
sum += product_promo_linker.promo.count;
});
return sum;
};
Ich versuchte mit
orderBy: product.getAllCounter()
und
orderBy: product.getAllCounter
Verfahren product.getAllCounter return integer
GELÖST
I verwendet:
<tr ng-repeat="campaign in results.data | orderBy: getAllCounter:true">
in meinem controller.js:
$scope.getCounter = function(product) {
return campaign.getAllCounter();
};
Bereits gibt es eine Frage ähnlich wie Ihr Problem. [Diese Frage prüfen] (http://stackoverflow.com/questions/12040395/custom-sort-function-in-ng-repeat) –