js对html内容进行排序,调用js内嵌函数sort对json数据排序

完整的html代码如下

Title

var jsonData={

"id": "e00101",

"name": "计量箱(柜)",

"deal": {

"keyname": "处理",

"type": "radio",

"values": [

{

"key": "create",

"value": "新建"

},

{

"key": "refresh",

"value": "刷新"

}

],

"key": "deal"

},

"values": [

{

"id": "Electric001@1471419400813",

"content": "2016-08-18 09:32:34"

},

{

"id": "Electric001@1471419400813",

"content": "2016-08-18 09:37:06"

},

{

"id": "Electric001@1471419400813",

"content": "2016-08-18 09:37:28"

},

{

"id": "Electric001@1471419400813",

"content": "2016-08-18 09:38:07"

},

{

"id": "Electric001@1471419400813",

"content": "2016-08-18 09:39:07"

},

{

"id": "Electric001@1471419400813",

"content": "2016-08-18 09:43:00"

}

]

};

function SortArrayByDate(jsonArray) {

var jsonArray2=[];

for(var index in jsonArray){

jsonArray2.push(jsonArray[index]);

}

//核心代码,sort函数的构造

jsonArray2.sort(function(json1,json2){

var date1=json1["content"];

var time1=new Date(date1).getTime();

var date2=json2["content"];

var time2=new Date(date2).getTime();

return time2-time1;

});

return jsonArray2;

}

var resulta= SortArrayByDate(jsonData.values);

var a=[];

for(var index in resulta){

a.push(resulta[index].id+":"+resulta[index].content);

}

document.getElementById('div').innerHTML=a;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值