Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 加载更多不起作用的帖子_Javascript_Jquery_Jquery Mobile - Fatal编程技术网

Javascript 加载更多不起作用的帖子

Javascript 加载更多不起作用的帖子,javascript,jquery,jquery-mobile,Javascript,Jquery,Jquery Mobile,我添加了一个LoadMore函数,根据DOM中当前显示的帖子长度和帖子总数追加更多帖子。我遇到的问题是,当我在控制台上记录帖子列表并检查GoogleChrome中的元素时,我看到长度显示为零(0)。我不确定我到底哪里出错了,或者我采取的方法是否正确,或者我是否应该先加载前4个帖子,然后创建一个新的单独函数来处理追加操作,从而将这两个函数分开 $(document).on('pagebeforeshow', '#blogposts', function() { //$.mobil

我添加了一个LoadMore函数,根据DOM中当前显示的帖子长度和帖子总数追加更多帖子。我遇到的问题是,当我在控制台上记录帖子列表并检查GoogleChrome中的元素时,我看到长度显示为零(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);

                }});
$(document).on('pagebeforeshow','#blogposts',function(){
//$.mobile.showPageLoadingMsg();
$.ajax({
url:“http://howtodeployit.com/category/daily-devotion/?json=recentstories&callback=",
数据类型:“json”,
jsonpCallback:“successCallback”,
async:true,
beforeSend:function(){$.mobile.showPageLoadingMsg(true);},
完成:函数(){$.mobile.hidePageLoadingMsg();},
成功:功能(数据){
var$listofposts=$('data');
log($listofposts);
var$loadMore=$listofposts.parent().find('.load more');
//log($loadMore);
currentPage=0;
postsPerPage=4;
var showMorePosts=函数(){
$offset=currentPage*postsPerPage,//初始值为0
posts=data.posts.slice($offset,$offset+postsPerPage);
控制台日志(posts);
$。每个(职位、职能(i、val){
//控制台日志(val);
$(“#postlist”).html();
var result=$('
  • ').append([$(“”,{html:val.title}),$(“”,{html:val.extract})]).wrapInner(“”); $('#postlist')。追加(结果); 控制台日志(结果); }); 如果(posts.length!==postsPerPage){ 警报(“真”); $loadMore.hide(); } currentPage++; $(“#postlist”).listview(); $(“#postlist”).listview(“刷新”); } showMorePosts(); $loadMore.on('click',showMorePosts); }});
  • 正在向jQuery询问文档中所有
    标记的列表。
    您可能需要使用
    $(数据)
    相反。

    啊,我想我一定是睡着了。没错。现在再看一个,既然元素“count”在object元素中,我该如何显示它。长度当前显示为1,但count显示的是帖子的确切数量11我想你会想找到要显示帖子计数的HTML元素,然后调用someth在其jQuery对象上类似于
    text(data.count)
    。如何实现这一点。对于jQuery来说仍然是新手,您需要能够找到要显示post计数的元素,因此让我们给它一个id(例如
    postCount
    )。我们现在可以使用jQuery(
    $(“#postCount”)
    )搜索它并覆盖它包含的文本:
    $(“#postCount”).text(data.count)
    。请记住,您必须在代码中有权访问
    数据
    对象的某个位置执行此操作。好的,我将尝试此操作并通知您
    var $listofposts = $('data');