2

我已经搜索并没有找到我的问题的答案。希望,我已经很好地搜索了!所以,这是我的问题:

<div id="{{expression.comment_id.$id}}" class="comments" ng-repeat="expression in expressions| orderBy:orderProp"

因此,orderBy 效果很好,但我有一个特定的需求: id 为 '0' 的 expression.comment_id 必须保持在最前面。

怎么能做到这一点?我想我必须使用个人过滤器,但我不确定这是更有效的解决方案。如果这是一个好方法,我该如何正确实施它?

谢谢你的帮助 !

4

1 回答 1

2

在这里你为你做了一个小提琴:http: //jsfiddle.net/sameersemna/81q9jwg9/

基本上你必须制作一个自定义 orderBy 过滤器:

<ul ng-repeat="expression in expressions | orderBy:myValueFunction">

在控制器中:

$scope.myValueFunction = function(expression) {
        if(expression.comment_id == 0){
            return expression.comment_id;
        }else{
            return expression.orderProp;
        }
    }
于 2014-10-26T11:52:21.957 回答