【问题标题】:contidional orderBy only on init AngularJS条件顺序仅由 oninit AngularJS
【发布时间】:2016-06-07 13:24:45
【问题描述】:

如何在视图初始化时只运行一次 orderBy 过滤器?我不希望我的列表在运行时重新排序。

<li ng-repeat="service in quote.services | orderBy:'index'" ></li>

【问题讨论】:

    标签: javascript angularjs ng-repeat angularjs-orderby


    【解决方案1】:

    在你的控制器中使用 orderBy 作为过滤器:

    app.controller('DemoCtrl', ['$scope', '$filter', function($scope, $filter){  
        $scope.quote.services = $filter('orderBy')($scope.quote.services, 'index');
    }]);
    

    请参阅filter docs 了解所有选项。

    【讨论】:

    • 谢谢,效果很好。我会尽快标记为答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-27
    • 2018-12-18
    • 2013-08-25
    • 2016-05-09
    • 2021-02-18
    • 1970-01-01
    相关资源
    最近更新 更多