【发布时间】:2016-05-01 10:41:41
【问题描述】:
我正在 jquery mobile 中创建一个应用程序,其最终输出应类似于以下内容:
生成该图像的原始 html 代码是
<ul data-role="listview" data-inset="true">
<li data-role="list-divider">Today, May 1, 2016 <span class="ui-li-count">2</span></li>
<li><a href="#">
<h3>Reply</h3>
<p>20,00 we do have discounts for earlier payers </p>
<p class="ui-li-aside">10 mins ago</p>
</a></li>
<li><a href="#">
<h4>Me</h4>
<p>How much is the current fee per semester? Do you accet credit cards</p>
<p class="ui-li-aside">25 mins ago</p>
</a></li>
<li data-role="list-divider">Yesterday, April 30, 2016 <span class="ui-li-count">1</span></li>
<li><a href="#">
<h3>Reply</h3>
<p>Hello, How can i help you?</p>
<p class="ui-li-aside">10:15 pm</p>
</a></li>
<li data-role="list-divider">Friday, April 29, 2016 <span class="ui-li-count">1</span></li>
<li><a href="#">
<h3>Me</h3>
<p>Hello</p>
<p class="ui-li-aside">10:15 pm</p>
</a></li>
</ul>
在我的项目中,我使用 json 从数据库中获取数据并在上面的列表视图中显示给用户。
从数据库中获取数据的代码:
var id_from = localStorage.loggedin_id;
var id_to_send = localStorage.user_schoolls_head;
$.getJSON("http://127.0.0.1/tum_old/custom/php/message.php",
{id_from:id_from,id_to_send:id_to_send},
function(response){
console.log(response);
});
在 console.log(response) 之后,我得到的 javascript 对象为:
带有列表的图片中的我的情况类似于 from_id 然后 to_id 的情况(例如 1:4),而回复则反之亦然。 如何格式化显示时间:
Today, yeasterday...from hence(on) it will display the dats on the list dividers
Time to show 10mins ago, 20mins ago, but beyond 1 hour it shows the actual time (eg: 10:15pm)
How to also sort these messages according to dates so that
the earliest is seen first in the today area..
ie:它应该像第一张图片一样
【问题讨论】:
-
看看这个小提琴:jsfiddle.net/ta793zx2/47 这(几乎)是你要找的吗?
-
快到了,但是如何根据日期添加列表分隔符
-
您可以对照数组检查日期。如果不存在,则生成分隔符 HTML 代码并将日期推送到数组。
-
你有一个关于如何在数组中精确推送日期的示例(你的意思)
-
请不要编辑您的帖子,以免其他答案无效。而是提出一个新问题。
标签: javascript jquery json jquery-mobile