Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 使用Select2 jquery一次性检索数据_Json_Jquery Select2 - Fatal编程技术网

Json 使用Select2 jquery一次性检索数据

Json 使用Select2 jquery一次性检索数据,json,jquery-select2,Json,Jquery Select2,我对select2组件(jQuery)有问题。 我有以下代码: $('#username').select2({ width: "400px", placeholder: "Selecteer 1 of meerder paritaire comités", style: "display; inline-block", minimumInputLength: 2, multiple: true,

我对select2组件(jQuery)有问题。 我有以下代码:

        $('#username').select2({
        width: "400px",
        placeholder: "Selecteer 1 of meerder paritaire comités",
        style: "display; inline-block",
        minimumInputLength: 2,
        multiple: true,
        ajax: {
            url: "/Prospect/_LoadParComs/",
            dataType: "json",
            type: "GET",
            data: function (searchTerm) {
                return {
                    query: searchTerm
                }
            },
            results: function (data, page) {
                return { results: data }
            }
        }
    });
现在它工作了,每次我点击htmlelement,我的数据都会被调用,我看到结果。当我单击某个项目时,该项目会显示在HtmleElement上,然后单击ok。但是每次我点击元素,它就会返回来检索我的数据,这需要时间,至少5秒。 难道不能加载一次数据并使用它吗?而不必一次又一次地获取数据


善良的问候

您不能添加一个初始化为false的控制变量,并在得到结果时更新为true吗?然后使用它来阻止下一次获取数据。我应该在哪里这样做?问候