按数字顺序angularjs NG重复排序字符串数组 [英] angularjs ng-repeat ordering string arrays in numerical order

查看:233
本文介绍了按数字顺序angularjs NG重复排序字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有帖子像ID的列表
1,2,3,4,5,6,7,8,9,10,11,12
(JSON格式)
该ID是String类型。不过,我想根据其数字顺序来订购吧
普通排序依据:'fiche.id列表显示如下。
1,10,11,12,2,3,4,5,6,7,8,9

I have a list of post with ids like 1,2,3,4,5,6,7,8,9,10,11,12 (json format) The ids are of type String. But I would like to order it according to its numerical order Normal orderBy:'fiche.id' the list is displayed as below. 1,10,11,12,2,3,4,5,6,7,8,9

我想输出是顺序 - 1,2,3,4,5,6,7,8,9,10,11,12

I would like the output to be of order - 1,2,3,4,5,6,7,8,9,10,11,12

推荐答案

我猜你的ID是字符串。一个简单的解决办法是使用无。里面ORDER BY操作。因此,而不是OFR 排序依据:ID只需使用排序依据:'标识* 1 这将考虑id作为无。并根据数字顺序排序。

I guess your ids are strings. A simple solution would be use a no. operation inside order by. So instead ofr orderBy:'id' just use orderBy:'id*1' this will consider the id as no. and sort it according to the numerical order.

这是你所需要的 - < D​​IV NG重复=缩微胶片的销售商|排序依据:'标识* 1'> {{fiche.id}}< / DIV>

This is all you need - <div ng-repeat="fiche in fiches | orderBy:'id*1'">{{fiche.id}}</div>

演示:<一href=\"http://plnkr.co/edit/MSrPTZQP49F7Nzwhv6ef?p=$p$pview\">http://plnkr.co/edit/MSrPTZQP49F7Nzwhv6ef?p=$p$pview

这篇关于按数字顺序angularjs NG重复排序字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆