自动完成是否适用于多个文件



我在我的项目上使用EasyAautocomplete。我想知道是否有可能在一个搜索框中使用2个不同文件的自动完成。我已经尝试超越代码,但它只读取其中一个:

<script>  
 var options = {    
 url: "file1.json",
 getValue: "name",
 list: {
 match: {
 enabled: true
         }
         },
   theme: "square"
        };
 $("#KUNDE").easyAutocomplete(options);$('div.easy-autocomplete').removeAttr('style');
         var options2 = {
            url: "file2.json",
            getValue: "name",
            list: {
              match: {
              enabled: true
                }
                },
            theme: "square"
        };
 $("#KUNDE").easyAutocomplete(options2);$('div.easy-autocomplete').removeAttr('style');
    </script>

我建议你:

  • 首先获取json文件
  • 合并它们
  • 使用它们自动完成

代码如下:

$.getJSON("file1.json", function (data1) {
    $.getJSON("file2.json", function (data2) {
        var mergedData = $.extend({}, data1, data2);
        var options = {
            data: mergedData,
            getValue: "name",
            list: {
                match: {
                    enabled: true
                }
            },
            theme: "square"
        };
        $("#KUNDE").easyAutocomplete(options); $('div.easy-autocomplete').removeAttr('style');
    });
});

最新更新