admin管理员组文章数量:1321051
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
I would like the output to be of order - 1,2,3,4,5,6,7,8,9,10,11,12
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
I would like the output to be of order - 1,2,3,4,5,6,7,8,9,10,11,12
Share Improve this question edited Jun 4, 2014 at 5:51 Raman Mandal 2761 silver badge6 bronze badges asked Jun 4, 2014 at 4:51 zelocalhostzelocalhost 1,1833 gold badges21 silver badges40 bronze badges 5- There is a missing id after 3. Is a part of json or typo mistake? – Vaibhav Magon Commented Jun 4, 2014 at 4:53
- Show your code, make a fiddle if you can – Mosho Commented Jun 4, 2014 at 4:59
- Json is like that : "fiche": { "id": "1", "date_creation": "2014-04-01 00:00:00", "date_modification": "2014-04-01 00:00:00" }, – zelocalhost Commented Jun 4, 2014 at 5:01
- Show your code, make a fiddle if you can – Mosho Commented Jun 4, 2014 at 5:03
- jsfiddle/bcKg6 – zelocalhost Commented Jun 4, 2014 at 5:08
2 Answers
Reset to default 10I 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.
This is all you need - <div ng-repeat="fiche in fiches | orderBy:'id*1'">{{fiche.id}}</div>
Demo: http://plnkr.co/edit/MSrPTZQP49F7Nzwhv6ef?p=preview
Ideally it should Print the correct list in ng-repeat using order-by. I am adding a fiddle example with the same.Its a basic example. Hope it helps
> http://jsfiddle/L45cE/
本文标签: javascriptangularjs ngrepeat ordering string arrays in numerical orderStack Overflow
版权声明:本文标题:javascript - angularjs ng-repeat ordering string arrays in numerical order - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742093577a2420409.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论