我正在尝试将选中的复选框放入数组(checkBoxArray)中,并使用 Select2 jQuery 插件通过 ajax 将其发送到我的 php 请求文件。但过滤器值始终为空。
//Here the checkBox array
$('.chkfilters').on("change", function() {
    var checkBoxArray = $('.chkfilters:checked').map(function(i,n) {
        return $(n).val();
    }).get(); //get converts it to an array
});
// Here the Select2 plugin
$(".searchInput").select2({
    placeholder: "Rechercher un article, une référence...",
    minimumInputLength: 3,
    ajax: {
        url: "/suggest",
        dataType: 'JSONP',
        type: 'GET',
        data: function (term, page, checkBoxArray) {
            return {
                q: term,
                page_limit: 10,
                page: page,
                filter : checkBoxArray
            };
        },
        results: function (data, page) {
            var more = (page * 10) < data.total;
            return {
                results: data.articles,
                more: more
            };
        }
    },
    createSearchChoice: function(term, checkBoxArray) {
        return {
                text:term,
                tform:'/recherche',
                filter : checkBoxArray
         };
    },
    ...
});