orderByでメソッドを使用するにはどうすればよいですか?ng-repeatでorderByメソッドを使用する
私は方法はないと財産ngのリピートから私の配列をソートしたいと思い:
の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戻り整数
は
を解決し
は、私が使用:私のcontroller.jsで
<tr ng-repeat="campaign in results.data | orderBy: getAllCounter:true">
:
$scope.getCounter = function(product) {
return campaign.getAllCounter();
};
は、すでにあなたの問題に類似の問題がある渡します。 [この質問をチェック](http://stackoverflow.com/questions/12040395/custom-sort-function-in-ng-repeat) –