javascript - jQuery for循环出来的数据,根据时间的先后,依次把DOM节点放在页面上?

查看:75
本文介绍了javascript - jQuery for循环出来的数据,根据时间的先后,依次把DOM节点放在页面上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

在接口中查询出来的数据是这样的:

"contents": [
{
"itemContent": "问题提出",
"createdOn": 2017-01-6,
"itemType": 0,
"imgs": []
},
{
"itemContent": "回答",
"createdOn": 2017-01-12,
"itemType": 2,
"imgs": []
},
{
"itemContent": "小毕",
"createdOn": 2017-01-12,
"itemType": 2,
"imgs": []
},
{
"itemContent": "456456465",
"createdOn": 2017-01-13,
"itemType": 2,
"imgs": []
},
{
"itemContent": "礼拜四",
"createdOn": 2017-01-13,
"itemType": 2,
"imgs": []
}
],

从数据中可以看出,查出来的数据是由时间的升序排序的,有什么方法让这个数组中的对象按时间倒序排列?
谢谢!
最后的结果是这样:

"contents": [
{
"itemContent": "礼拜四",
"createdOn": 2017-01-13,
"itemType": 2,
"imgs": []
},
{
"itemContent": "456456465",
"createdOn": 2017-01-13,
"itemType": 2,
"imgs": []
},
{
"itemContent": "小毕",
"createdOn": 2017-01-12,
"itemType": 2,
"imgs": []
},
{
"itemContent": "回答",
"createdOn": 2017-01-12,
"itemType": 2,
"imgs": []
},
{
"itemContent": "问题提出",
"createdOn": 2017-01-6,
"itemType": 0,
"imgs": []
}
]

解决方案

var arr = contents.reverse();

这篇关于javascript - jQuery for循环出来的数据,根据时间的先后,依次把DOM节点放在页面上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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