gpt4 book ai didi

javascript - 条件顺序仅由 oninit AngularJS

转载 作者:搜寻专家 更新时间:2023-11-01 05:21:36 25 4
gpt4 key购买 nike

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

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

最佳答案

改为在 Controller 中使用 orderBy 作为过滤器:

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

参见 filter docs对于所有选项。

关于javascript - 条件顺序仅由 oninit AngularJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35615976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com