0

其他人之前已经问过这个问题,但没有提供任何答案。实际上,目标是使用 Django 的 Twitter 风格的无限分页来实现搜索功能。用户修改了一些界面字段,并且考虑到新的用户输入,无限表重新初始化。

我有一个模板 A ,它是包含嵌入式模板 B的主模板,用作我的无尽表的容器。该表在用户向下滚动时加载附加数据:

<select id = 'parameter' class="form-control input-sm">
    <!-- my options -->
</select>
<table>
   <thead>...</thead>
   <tbody>
         {% include 'my_app/template_B.html' %}
   </body>
</table>

模板 B 的结构似乎与问题无关,所以让我省略它。

初始化模板 A 的 Django 视图:

def my_view(request,\
            parameter_id = None,
            template='order_scheduler/template_A.html',\
            extra_context=None):
if parameter_id is None:
   # do smth
else:
   # do smth
return render_to_response(template,
                          context,
                          context_instance=RequestContext(request)): 

问题:当用户修改参数组合框的值而不刷新模板A时,如何重新初始化模板B中的无限表?

4

1 回答 1

1

template_B.html您可以创建一个根据 POST 中传递的参数呈现的视图,然后在您的页面中:

    $(function() {
        var parameter = $('#parameter');
        parameter.on('change', function() {
            $.post("/your/viev/url", {'parameter': parameter.val()}, function(response) {
                $('tbody').html(response);
            });
        });
    });
于 2016-07-26T14:19:59.760 回答