In the previous question I had a problem with filtering. With this sorted out. Now I have another problem, I can’t fix it, I tried it all. In one stanichka I do 5 selektov with the help Select2. The problem is that the first select works as expected. Filters words and lists them in bold in the list. But in the rest it does not work out this way, in other words, the written word in the select code is not bold:
// article $(".search_article select").select2({ ajax: { url: "/index.php/search/jsonTags?type=0", dataType: 'json', delay: 250, async: true, cache: true, data: function(params) { return { query: params.term, page: params.page }; }, processResults: function(data, params) { var items = $.map(data, function(item, i, params) { return { text: item.tag, slug: item.tag, id: item.tag }; }); return {results: items}; } }, minimumInputLength: 3, placeholder: "Введите ариткул", language: "ru", templateResult: function (data) { if (data.id === '') { // adjust for custom placeholder values return 'Custom styled placeholder text'; } var term = $('.select2-search__field').val(); var $text = $('<span>'+data.text.replace(term, '<strong>'+term+'</strong>')+'</span>'); return $text; } }); // material $(".material select").select2({ ajax: { url: "/index.php/search/jsonTags?type=2", dataType: 'json', delay: 250, async: true, cache: true, data: function(params) { return { query: params.term, page: params.page }; }, processResults: function(data, params) { var items = $.map(data, function(item, i, params) { return { text: item.tag, slug: item.tag, id: item.tag }; }); return {results: items}; } }, minimumInputLength: 3, placeholder: "Введите материал", language: "ru", templateResult: function (data) { if (data.tag === '') { // adjust for custom placeholder values return 'Custom styled placeholder text'; } var term = $('.select2-search__field').val(); var $text = $('<span>'+data.text.replace(term, '<strong>'+term+'</strong>')+'</span>'); return $text; } }); HTML:
<div class="search_article"> <span>Артикул</span> <select name="article" id="article" multiple="multiple"></select> </div> <div class="material"> <span>Материал</span> <select name="material" id="material" multiple="multiple"></select> </div> $('<span>'+data.text.replace(term, '<strong>'+term+'</strong>')+'</span>');
This line is responsible for this), but why it cannot work a second time I cannot understand. data.text.replace (() function

