我将select2与Ajax一起使用。我在前端有一些fa图标,并希望通过创建新标签将其插入:
$("#idSelectPacketName").select2({
cache: true,
tags: true,
placeholder: inputPlaceholderNamePacket,
tokenSeparators: [','],
ajax: {
url: './../../back-end/switch-ajax-listening/switch-ajax-listening.php',
type: "post",
dataType: 'json',
delay: 250,
data: function (params)
{
return {
searchTerm: params.term, // search term
actionId: "getSelector",
jsonField: "idSelectPacketName"
};
},
processResults: function (response)
{
return {
results: response,
id: response.term,
text: response.term + " (new)",
newOption: true
};
},
},
createTag: function (params)
{
var term = $.trim(params.term);
if (term === '')
{
return null;
}
//console.log(term.length);
if(term.length>50)
{
alertError("The name packet must be less than 50 char");
return null;
}
return {
id: term,
text: term + ' (new)' //Here I have tried something
};
},
});
我尝试插入:
text: $('<i class="fa fa-sitemap"></i>Branch name'),
我也尝试过这样:
text: ('<i class="fa fa-sitemap"></i>Branch name'),
但是结果不好。 Select2会打印出来,仅此而已。
您有一些想法可以解决吗?我希望看到带有新文字的fa图标。