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

标签 javascript jquery jquery-select2

我正在使用 Select2 和 ajax 选项,它是一个多选框。我能够第一次选择记录。但是在选择第一个之后,如果我尝试选择下一个,它就不起作用。

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          
  })

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

最佳答案

从代码中删除以下 block

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

},

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

我已经为相同的内容创建了一个演示[在您的示例中进行了编辑]

只需引用此网址

https://jsfiddle.net/7m2nv5yw/

关于javascript - 第二次选择时 Select2 显示 "No result found"消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59703494/

相关文章:

javascript - 使用 AngularJS 从 Unsplash 预加载随机图像

javascript - 正则表达式 javascript 网站以/结尾

jquery - Bootstrap 崩溃数据目标选择器失败

javascript - 使用 jquery 或 JS 从现有值集中过滤结果

twitter-bootstrap - Select2 4.0.0 Bootstrap 主题

javascript - angular-ui select2 initSelection 没有被调用

javascript - 从下拉列表中的数据库中获取值

jquery - 使用 jstree 检索取消选择的节点

javascript - 添加图标到 select2 不基于值

javascript - 误报 "Unreachable code detected.ts(7027)"?