Select drop-down search (Select2 freezes when the amount of data is large)

Scenario: I encountered an old project with front-end and back-end integration that used Select2. The data under select were all brought over at once through controllers. Later, when the amount of data increases, serious lagging problems will occur when Select2 switches options.

Some people may say that it is not enough to use paging loading. But after trying it, I found that after loading a certain amount of data, switching options will also cause problems.

Finally decided to give up using Select2 and write my own select drop-down search

File link: https://download.csdn.net/download/weixin_44646763/86247616

gitHub link: https://github.com/1499610503/search_select

Because jq is used in the code, jq needs to be introduced before introducing search_select.js

Also don’t forget to introduce search_select.css

Instructions:

var ss1 = new SearchSelect('#text_search_select',{
    
    placeholder:'输入搜索内容'})

The first parameter is the css selector of the target select element. If placeholder is not passed, it defaults to empty.
placeholder is the placeholder value of the search input.

Additional items can be added to the select:

            ss1.addSelectOption([{
    
    
                value: 5,
                text: 'option5'
            }, {
    
    
                value: 6,
                text: 'option6'
            }, {
    
    
                value: 7,
                text: 'option7'
            }, {
    
    
                value: 8,
                text: 'option8'
            }, ])

Guess you like

Origin blog.csdn.net/weixin_44646763/article/details/125928447