select2 search - match only words that start with search term

前端 未结 2 1741
被撕碎了的回忆
被撕碎了的回忆 2021-01-11 11:22

I migrated from chosen to select2 plugin because it works better for me, but its documentation is very poor when compared to chosen. Could anyone tell me what option(s) shou

2条回答
  •  执念已碎
    2021-01-11 12:16

    Select2 4.0.0

    function matchStart(params, data) {
        params.term = params.term || '';
        if (data.text.toUpperCase().indexOf(params.term.toUpperCase()) == 0) {
            return data;
        }
        return false;
    }
    
    $("select").select2({
        matcher: function(params, data) {
            return matchStart(params, data);
        },
    });

提交回复
热议问题