我有一个 id 像这样的帖子列表
1,2,3,4,5,6,7,8,9,10,11,12
(json 格式)
ids 是 String 类型。但是我想按照它的数字顺序来排序
正常 orderBy:'fiche.id' 列表显示如下。
1,10,11,12,2,3,4,5,6,7,8,9
我希望输出是有序的 - 1,2,3,4,5,6,7,8,9,10,11,12
最佳答案
我猜你的 ID 是字符串。一个简单的解决方案是使用 no。 order by里面的操作。所以而不是orderBy:'id'
只需使用 orderBy:'id*1'
这会将 id 视为否。并根据数字顺序对其进行排序。
这就是您所需要的 - <div ng-repeat="fiche in fiches | orderBy:'id*1'">{{fiche.id}}</div>
关于javascript - angularjs ng-repeat按数字顺序排序字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24029265/