0
我添加一个LoadMore函数来根据当前显示帖子的长度和DOM中的帖子总数追加更多的帖子。我遇到的问题是当我登录listofposts控制台并检查Google Chrome中的元素时,我看到长度显示为零(0)。我不确定我到底出错的地方,或者我采取的措辞是对的,还是应该先分开这两个函数,首先加载前4个帖子,然后创建一个独立的新函数来处理追加?加载更多的帖子不工作
$(document).on('pagebeforeshow', '#blogposts', function() {
//$.mobile.showPageLoadingMsg();
$.ajax({
url: "http://howtodeployit.com/category/daily-devotion/?json=recentstories&callback=",
dataType: "json",
jsonpCallback: 'successCallback',
async: true,
beforeSend: function() { $.mobile.showPageLoadingMsg(true); },
complete: function() { $.mobile.hidePageLoadingMsg(); },
success:function(data){
var $listofposts = $('data');
console.log($listofposts);
var $loadMore = $listofposts.parent().find('.load-more');
// console.log($loadMore);
currentPage = 0;
postsPerPage = 4;
var showMorePosts = function() {
$offset = currentPage * postsPerPage, //initial value is 0
posts = data.posts.slice($offset, $offset + postsPerPage);
console.log(posts);
$.each(posts, function(i, val) {
//console.log(val);
$("#postlist").html();
var result = $('<li/>').append([$("<h3>", {html: val.title}),$("<p>", {html: val.excerpt})]).wrapInner('<a href="#devotionpost" onclick="showPost(' + val.id + ')"></a>');
$('#postlist').append(result);
console.log(result);
});
if(posts.length !== postsPerPage){
alert ('True');
$loadMore.hide();
}
currentPage++;
$("#postlist").listview();
$("#postlist").listview('refresh');
}
showMorePosts();
$loadMore.on('click', showMorePosts);
}});
啊我想我一定在睡觉。这是正确的。现在还有一件事,我怎么显示元素'count',因为它在object元素中。该长度当前显示1,但计数正在显示帖子的确切数量11 – Chelseawillrecover
我想你会希望找到HTML元素,你想显示帖子数,并在其jQuery上调用像'text(data.count)'的东西目的。 –
我该如何做到这一点。仍然是Jquery的新功能 – Chelseawillrecover