基本上,當我點擊第一頁並點擊按鈕時,它應該顯示前兩個動態帖子。不幸的是,只有在前兩個帖子出現之前,我在瀏覽器上點擊刷新按鈕後纔會顯示帖子。初始頁面空白,直到頁面刷新
我花了幾個小時試圖找出我在此代碼是缺少:
$(document).ready(function() {
var data = $.getJSON("http://howtodeployit.com/category/daily-devotion/feed/?json=recentstories", function(data) {
var $postsList = $('#postlist'),
$loadMore = $postsList.parent().find('.load-more'),
currentPage = 0,
postsPerPage = 2;
var showMorePosts = function() {
var offset = currentPage * postsPerPage,
posts = data.posts.slice(offset, offset + postsPerPage);
$.each(posts, function (i, val) {
$('<li/>').append([$("<h3>", {html: val.title}),$("<p>", {html: val.excerpt})]).wrapInner('<a href="#devotionpost" onclick="showPost(' + val.id + ')"></a>').appendTo($postsList);
});
if(posts.length !== postsPerPage) {
$loadMore.hide();
}
currentPage++;
$postsList.listview('refresh');
};
$postsList.listview();
showMorePosts();
$loadMore.on('click', showMorePosts);
});
});
HTML:
<!-- Page: home -->
<div id="home" data-role="page" data-theme="d" data-title="My Devotion">
<div data-role="listview">
<a href="#devotion" id="devotionclick" data-role="button">Daily Devotional Messages</a>
</div><!-- links -->
</div><!-- page -->
<!-- Page: Daily Devotional Messages -->
<div id="devotion" data-role="page" data-title="My Devotion">
<div data-role="header" data-theme="a" data-position="fixed"> <h2>Daily Devotional Messages</h2></div><!-- header -->
<ul data-theme="d" id="postlist"> </ul><!-- content -->
<div class="load-more">Load More Posts...</div>
</div><!-- page -->
也看到這樣的錯誤:
Uncaught TypeError: Cannot read property 'jQuery1101005234554712660611' of undefined
您的代碼在哪行看到錯誤?由「$ postsList.listview();」引起的「 –
」 – Chelseawillrecover