初始化jplist后如何添加复选框过滤器项

How to add checkbox filter item after initialize jplist

我有 3 个 ajax 从 3 个不同的网站调用 curl。 当第一个 ajax 完成时,我将初始化 jplist,然后 ajax 将添加到列表中。 问题是我需要从初始化后的下一个 ajax 添加项目到复选框过滤器,所以它意味着动态过滤器项目。 现在工作过滤器是来自第一个 ajax.

的过滤器

如何在初始化后从下一个 ajax 添加过滤器? 我之所以在第一个 ajax 之后进行初始化是因为我不想让用户等到所有 ajax 完成,因为这需要时间。

谢谢。

我遇到了同样的问题,我是这样解决的:

var jpl = function(){
    $('#demo').jplist({
        itemsBox: '.files',
        itemPath: '.contentitem',
        panelPath: '#filters-container',
        noResults: '.jplist-no-results',
        dataSource: {
            type: 'server',
            server: {
                ajax: {
                    url: '/api/files',
                    dataType: 'json',
                    type: 'POST'
                }
            },
            render: function(dataItem, statuses) {
                $list.html(template(dataItem.content));
            }
        }
    });
}
$("body").on('click', '.morenav>a', function(ev){
    ev.preventDefault();
    ev.stopPropagation();
    var href = $(this).attr('href');
    var mn = $(this).closest('.morenav');
    $.ajax({
        type: "POST",
        dataType: 'json',
        url: href,
        contentType: "application/json; charset=utf-8",
        success: function (data) {
            $(data['content']).insertBefore(mn); // <===== put html content from ajax return here
            jpl(); // <===== call jplist again after ajax call here
        },
        error: function(data){
            console.log("ERROR ", data);
        },
    });
});
jpl(); // <===== call jplist here

其中 json api return:

{
     'page': 2,
     'content': '<input data-path=".the_path" type="checkbox" id="the_chkbox" name="the_chkbox" value="1" >',
}