我正在使用 autodividersSelector 函数将发布日期显示为分隔符文本。我被困在如何导航以检索日期类的问题上。下面是 DOM 中 Div 元素的代码和控制台日志。
如果此问题已在其他地方得到解答,请提供链接。谢谢
代码
$(document).on('pagebeforeshow', '#blogposts', function () {
$.ajax({
url: "http://howtodeployit.com/category/daily-devotion/feed/?json=recentstories" ,
dataType: "json" ,
beforeSend: function () {$('.loader').show();},
complete: function () {$('.loader').hide();},
success: function (data){
$('#postlist').empty();
//setTimeout(function(){
$.each(data.posts, function (key, val) {
//Format date
var dateString = val.date.split(' ')[0];
var vdate = dateString.split("-")[1] + " " + monthStrings[parseInt(dateString.split("-")[1])] + ", " + dateString.split("-")[0];
//Output data collected into page content
var rtitle = $('<p/>', {'class' : 'vTitle', html: val.title}); rdate = $('<p/>', {'class': 'vDate' , html: vdate});
rid = $('<a href="#d-posts" onclick="showPost(' + val.id + ')"></a>');
var rappend = $('<li/>').append(rtitle, rdate);
$('#postlist').append($(rappend).wrapInner(rid).fadeIn(600));
$('#postlist').listview({
autodividers: true,
autodividersSelector: function (li) {
//console.log(li);
var out = $(li).get(0)
console.log(out);
return out;
}
});
return (key !== 5);
});
$("#postlist").listview().listview('refresh').append('<div class="more-posts" style="text-align: center;">Load more posts...</div>');
// }, 2000);
},
error: function (data) {
alert("Service currently not available, please try again later...");
}
});
});
在分隔符中显示 [objectHTMLLiElement] 的输出结果
HTML:
<!-- Page: Blog Posts -->
<div id="blogposts" data-role="page">
<div data-role="header" data-position="fixed">
<h2>My Blog Posts</h2>
</div><!-- header -->
<div data-role="listview">
<ul data-filter="true" data-filter-placeholder='Search blog posts...' data-theme="a" id="postlist"> </ul><!-- content -->
</div>
<div class="loader"><img src="css/images/loader.gif"/></div>
</div><!-- page -->