jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了寻找一种方法来动态添加更多列表到jQuery Mobile listview的底部大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在寻找一种方法,在向下滚动后在列表视图底部添加更多列表.例如,我最初返回20个项目.我打算使用分页,只返回从我的查询返回的数量,但我宁愿返回15-20然后在滚动结束时自动添加更多此列表或有一个按钮说“查看更多” .我是jQuery Mobile的新手,想知道是否有人见过这种事情.这也用在Phonegap中.如果是这样,你能指出我正确的方向吗?非常感谢提前!

解决方法

而不是自动加载更多列表项,我建议放置一个按钮,用户可以点击加载更多(但这只是我的建议).
//setup an interval so we can throttle the `scroll` event handler since there will be tons of `scroll` events fired
var timer    = seTinterval(function () {
        scrollOK = true;
    },100),//run this every tenth of a second
    scrollOK = true;//setup flag to check if it's OK to run the event handler
$(window).bind('scroll',function () {

    //check if it's OK to run code
    if (scrollOK) {

        //set flag so thE interval has to reset it to run this event handler again
        scrollOK = false;

        //check if the user has scrolled within 100px of the bottom of the page
        if ($(this).scrollTop() + $(this).height() >= ($(document).height() - 100)) {
            //Now load more list-items because the user is within 100px of the bottom of the page
        }
    }
});

这是一个演示:http://jsfiddle.net/knuTW/

更新

只需加载一个用户可以点击的按钮,然后在点击它时,加载更多的行,然后将load-more按钮重新附加到列表的末尾,这样会容易一些:

var $loadMore = $('ul').children('.load-more');
$loadMore.bind('click',function () {
    var out = [];
    for (var i = 0; i < 10; i++) {
        out.push('<li>' + (count++) + '</li>');
    }
    $('ul').append(out.join('')).append($loadMorE).listview('refresh');
});

这是一个演示:http://jsfiddle.net/knuTW/2/

大佬总结

以上是大佬教程为你收集整理的寻找一种方法来动态添加更多列表到jQuery Mobile listview的底部全部内容,希望文章能够帮你解决寻找一种方法来动态添加更多列表到jQuery Mobile listview的底部所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。