我有這種格式的JSON響應:如何根據json響應顯示數據明智嗎?
[{"message":"fsbdfs","id":"8290","readBy":"2016-05-25 06:17:01","userID":"339","dateTime":"2016-05-25
06:16:32"},{"message":"Hi","id":"8291","readBy":"2016-05-25 06:33:52","userID":"332","dateTime":"2016-05-25
06:17:06"},{"message":"nbfsdbf","id":"8292","readBy":"","userID":"339","dateTime":"2016-05-25 07:03
:44"},{"message":"jsdhfjsdhf","id":"8293","readBy":"","userID":"339","dateTime":"2016-05-25 07:06:55"
},{"message":"fbsnf","id":"8294","readBy":"","userID":"339","dateTime":"2016-05-25 07:06:59"},{"message"
:"dfgjdf","id":"8295","readBy":"","userID":"339","dateTime":"2016-05-25 07:08:14"},{"message":"sim","id"
:"8296","readBy":"","userID":"339","dateTime":"2016-05-25 07:24:24"},{"message":"mgmdf,","id":"8297"
,"readBy":"","userID":"339","dateTime":"2016-05-25 10:16:34"},{"message":"bvd","id":"8317","readBy":""
,"userID":"339","dateTime":"2016-05-31 06:25:40"},{"message":"fdfd","id":"8318","readBy":"","userID"
:"339","dateTime":"2016-05-31 06:25:43"}]
我想聰明的聊天中顯示框,但迄今爲止這些消息像第一場演出日期25 2015年5月則在此顯示信息,所有與該日消息在新的日期到來之後它顯示在下一次2015年5月31日的留言1留言2等等。
而我打印這樣,它只是附加信息,但我需要 過濾日期和時間。
for (i = 0; i < msg1.length; i++) {
var el = $('<li class="message right appeared"><div class="avatar"><img src="'+url+'/service/getUserImage/'+msg1[i].userID +'/60"/></div><div class="text_wrapper"><div class="text">'+msg1[i].message+'</div></div></li>');
$(".chat_window ul").append(el);
}
你忘了添加代碼 –
那麼,有什麼問題呢?目前,您似乎在問如何解析JSON,對數組進行排序,遍歷數組並向DOM添加新內容。哪些問題給你帶來麻煩?你已經做了什麼研究來嘗試自己解決它? – Quentin
您應該必須從db orderby desc中使用日期字段過濾掉數據。 –