如何使用orderBy方法?使用orderBy in ng-repeat方法
我想从纳克重复我的数组的属性与排序的方法,而不是:
的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;
};
我试过
ORDERBY:product.getAllCounter()
和
ORDERBY:product.getAllCounter
方法product.getAllCounter返回整数
解决
我用:
<tr ng-repeat="campaign in results.data | orderBy: getAllCounter:true">
在我controller.js:
$scope.getCounter = function(product) {
return campaign.getAllCounter();
};
已经有类似于你的问题的问题。 [检查这个问题](http://stackoverflow.com/questions/12040395/custom-sort-function-in-ng-repeat) –