• bootstrap插件--select2.js--一个基于jQuery的替换框


    当然,首先需要引入,select2.css,jquery,boostrap.js,select2.js

    多选     添加属性

    multiple="multiple"
    function formatRepoProvince(repo) {
        if (repo.loading) return repo.text;
        var markup = repo.name;
        return markup;
      }
      function formatRepoSelection (repo) {
        return repo.name || repo.text;
      }
    
      // 远程筛选
      $(".select2").select2({
        
        ajax: {
          url: 'v2/enterprise/searchListPaging.do',
          delay: 500,
          method: "post",
          data: function (params) {
            return {
              keyword: params.term ? params.term : '',
              skip: 0
            }
          },
          processResults: function (data) {
            return {
              results: data.data.items,
            }
          },
        },
        placeholder: '公司名称',
        escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
        minimumInputLength: 1,
        templateResult: formatRepoProvince,
        templateSelection: formatRepoSelection
      })

     踩坑点

    下拉框如果在bootstrap模态框中,input不会聚焦

    解决方案1:
    在bootstrap.js中修改:
    Modal.prototype.enforceFocus = function () {
    $(document)
    .off('focusin.bs.modal') // guard against infinite focus loop
    .on('focusin.bs.modal', $.proxy(function (e) {


    //以下为加入代码
    if ($(e.target).hasClass('select2-search__field')) {
    return true;
    }
    //加入代码结束


    if (this.$element[0] !== e.target && !this.$element.has(e.target).length) {
    this.$element.trigger('focus')
    }
    }, this))
    }

    解决方案2:

     说明绑定给哪个父级

    dropdownParent: $('#onlineApply'),

    参考地址:https://github.com/select2/select2

    https://select2.org/

  • 相关阅读:
    再探最大公约数
    非旋treap
    初赛毒瘤汇总(持续更新中)
    架构漫谈阅读笔记五--以豆瓣得基础架构为例
    架构设计小论文
    第一阶段
    架构漫谈阅读笔记六--以淘宝数据魔方技术架构解析为例
    学习进度第八周
    架构漫谈阅读笔记一
    软件架构之 Refined Architecture阶段
  • 原文地址:https://www.cnblogs.com/tianxinyu/p/9988763.html
Copyright © 2020-2023  润新知