第二次选择时,Select2 显示 "No result found" 消息

Select2 is showing "No result found" message when selecting second time

我正在使用带有 ajax 选项的 Select2 及其多个 selection 盒。我能够 select 第一次记录。但是在 select 第一个之后,如果我尝试 select 下一个,它就不起作用了。

fiddle link for complete code

$('#select2_ajax_complex_id').select2({
    tags: true,
    maximumSelectionSize: 10,
    minimumResultsForSearch: Infinity,
    multiple: true,
    minimumInputLength: 1,
    placeholder: "Search Employee",
    //data:o,
    id: function(i) {
      return i;
    },
    initSelection: function(element, callback) {

    },
    ajax: {
      type: 'post',
      url: "/echo/json/",
      allowClear: true,
      dataType: 'json',
      delay: 250,
      params: {
        contentType: "application/json"
      },
      data: function(term, page) {
        //Code for dummy ajax response
        return {
          json: complex_employee_response,
          delay: 0
        };
      },
      results: function(data, page) {
        return {
          results: data
        };
      },
      cache: false
    },
    formatResult: function(i) {
      return '<div>' + i.name + '(' + i.role + ')' + '</div>';
    }, // Formats results in drop down
    formatSelection: function(i) {
      return '<div>' + i.name + '(' + i.role + ')' + '</div>';
    }, //Formats result that is selected
    dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
    escapeMarkup: function(m) {
        return m;
      } // we do not want to escape markup since we are displaying html in results          
  })

有人可以看看并帮助解决这个问题吗?

从您的代码中删除以下块

//data:o,
id: function(i) {
  return i;
},
initSelection: function(element, callback) {

},

通过使用此代码,您的问题将得到解决

我已经创建了一个相同的演示[在你的例子中编辑]

参考这个URL

https://jsfiddle.net/7m2nv5yw/