gpt4 book ai didi

angularjs - orderBy 在简单数组上?

转载 作者:行者123 更新时间:2023-12-04 23:02:22 26 4
gpt4 key购买 nike

我有一个这样的数组:

$scope.telcodes = ['44', '01', '221', '335'];

如何在像这样的简单数组上使用 orderBy 来生成从 01 开始的有序列表?

我知道如何在包含对象的数组上执行此操作,但不知道如何在上述简单数组上执行此操作。
<li data-ng-repeat="telcode in telcodes | orderBy:????:false track by $index">

最佳答案

您可以声明简单 proxy在您的 Controller 中运行并使用它:

Controller :

$scope.proxy = function(x) { return x; }

HTML:
<tr ng-repeat="t in telcodes | orderBy: proxy">

但是,它为您提供字符串比较( demo )。

要获得标准数字比较,请修改 proxy一点点( demo ):
$scope.proxy = function(x) { return x * 1; }

关于angularjs - orderBy 在简单数组上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20109119/

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