且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Django应用程序中加载更多内容?

更新时间:2023-10-20 12:12:28

1。将object_list解析为JSON对象:这应该允许您为客户端提供存在的所有组,以实现使用户保持在同一页面上的目标。

1. Parse the object_list into a JSON object: This should allow you to provide the client with all the groups that exist in order to achieve your goal to keep the user on the same page.



2。使用jQuery或Javascript刷新具有列出的组的html容器:根据数据的大小和类型,您还可以编写一个新视图,将过滤后的JSON对象返回给Javascript中的post方法。


2. Use jQuery or Javascript to refresh your html container that has the groups listed: Based on the size and type of data, you can also write a new view that returns a filtered JSON object to a post method in Javascript.

示例: https://codepen.io/elmahdim / pen / sGkvH

    /*
     Load more content with jQuery - May 21, 2013
    (c) 2013 @ElmahdiMahmoud
    */   

$(function () {
    $("div").slice(0, 4).show();
    $("#loadMore").on('click', function (e) {
        e.preventDefault();
        $("div:hidden").slice(0, 4).slideDown();
        if ($("div:hidden").length == 0) {
            $("#load").fadeOut('slow');
        }
        $('html,body').animate({
            scrollTop: $(this).offset().top
        }, 1500);
    });
});

$('a[href=#top]').click(function () {
    $('body,html').animate({
        scrollTop: 0
    }, 600);
    return false;
});

$(window).scroll(function () {
    if ($(this).scrollTop() > 50) {
        $('.totop a').fadeIn();
    } else {
        $('.totop a').fadeOut();
    }
});