Using SELECT2 4.0.0 with infinite Data and filter

后端 未结 2 1183
误落风尘
误落风尘 2021-02-04 13:33

I\'m using Select2 now since 2 years and I really enjoy all dev made. however, version 3.5.x has his limit, so I\'m moving to version 4.0, which give me headaches!

For y

2条回答
  •  情书的邮戳
    2021-02-04 14:12

    Simple way to underline matched results with select2 4.x

    $element.select2({
    
        escapeMarkup: function (markup) { return markup; }
        ,
         templateResult: function (result) {
            return result.htmlmatch ? result.htmlmatch : result.text;
         }
        ,
        matcher:function(params, data) {
            if ($.trim(params.term) === '') {
              return data;
            }
            if (typeof data.text === 'undefined') {
              return null;
            }
    
            var idx = data.text.toLowerCase().indexOf(params.term.toLowerCase());
            if (idx > -1) {
              var modifiedData = $.extend({
                  'htmlmatch': data.text.replace(new RegExp( "(" + params.term + ")","gi") ,"$1")
              }, data, true);
    
              return modifiedData;
            }
    
            return null;
        }
    })
    

提交回复
热议问题