Javascript 在jquery移动列表视图中格式化json内容
我正在jquery mobile中创建一个应用程序,其最终输出应类似于以下内容:Javascript 在jquery移动列表视图中格式化json内容,javascript,jquery,json,jquery-mobile,Javascript,Jquery,Json,Jquery Mobile,我正在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>&
生成该图像的原始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>
在console.log(response)之后,我得到如下javascript对象:
从带有列表的图片中,A me情况类似于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:它应该看起来像第一张图片
我的数据库记录:
要格式化日期,可以使用momentjs()。只需在sql查询中按时间添加排序即可实现排序 使用javascript对对象进行排序是非常不明智的。 正如Zoran所说,您应该在查询中使用
orderbytime\u send DESC
更新
不确定基于日期的除法器是什么意思,但我已经更新了JSFIDLE,以便在您的示例中准确地输出日期的格式。
希望有帮助。看看这把小提琴:这(几乎)就是你要找的吗?它几乎就在那里了,但我如何根据日期添加列表分隔符?你可以对照数组检查日期。如果没有,生成HTML代码并将日期推送到数组中。你有没有关于如何在数组中推送日期的示例(你的意思是什么)请不要编辑你的帖子,这样会使其他答案无效。相反,你可以问一个新问题。根据日期划分的列表分隔符是什么
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..