在ajax jquery中对数组进行排序 [英] Sort array in ajax jquery

查看:128
本文介绍了在ajax jquery中对数组进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须显示聊天记录。我有id,姓名,日期(日期时间)和消息。



但我必须根据日期和时间对数据进行排序。

我当前的结果正好相反



例子

msg 11:43 pm

msg 11:41 pm

msg 11:40 pm



见示例第一条记录最后是requird;我的意思是相反的顺序。



我尝试过:



i have to display chat history. i have id,name,date(datetime),and message.

but i have to sort data accroding to date and time.
my current result is exactly reverse

example
msg 11:43 pm
msg 11:41 pm
msg 11:40 pm

see example first record is requird at last; i mean in reverse order.

What I have tried:

function list() {
    debugger;
    $.ajax({

        url: "ListUsermsg",
        type: "POST",
        success: function (result) {  //if this result is sort accordint //date and time then my issue will solve. in result each array contain id,uname,datetime,msg,photo of value.

            $.each(result, function (Index, item) {
               
                var data = '' +
               ' ' + item.uname + ' ' +
                ' ' + item.time + ' ' +
                ' ' + item.msg +'</td' > +
                ' ' + item.photo +' ' +
                ' ' 
                $("#chathistory").append(data);
            })


        }
    });
}

推荐答案

.ajax({

url: ListUsermsg
type: POST
成功:功能结果){ // 如果这个结果是sort accordint //日期和时间,那么我的问题将解决。结果每个数组包含id,uname,datetime,msg ,价值照片。
.ajax({ url: "ListUsermsg", type: "POST", success: function (result) { //if this result is sort accordint //date and time then my issue will solve. in result each array contain id,uname,datetime,msg,photo of value.


.each(结果,功能(索引,项目){

var data = ' ' +
' ' + item.uname + ' ' +
' ' + item.time + ' ' +
' ' + item.msg + ' < / td'> +
' ' + item.photo + ' ' +
' '
.each(result, function (Index, item) { var data = '' + ' ' + item.uname + ' ' + ' ' + item.time + ' ' + ' ' + item.msg +'</td' > + ' ' + item.photo +' ' + ' '


#chathistory) .append(数据);
})


}
});
}
("#chathistory").append(data); }) } }); }


这篇关于在ajax jquery中对数组进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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