如何在select2的选定项中显示图标
How to display an icon in the chosen item of select2?
我有一个<options>
格式化的select2插件。我在右边添加了一个漂亮的图标。
问题是,当我选择任何有图标的项目时,当下拉菜单关闭时,图标不会显示在所选的当前项目中。怎么解呢?可能是格式功能出错了?
这里是一个jsfiddle,你可以尝试:http://jsfiddle.net/uAnLJ/18/
JS
$("#mysel").select2({
width: "100%",
formatResult: function(referencia) {
if (!referencia.id) return referencia.text; // optgroup
if ($(referencia.element).data('active') == "1") {
return referencia.text + "<i class='fa fa-check-circle'></i>";
} else {
return referencia.text;
}
}
});
CSS
body {
padding: 20px;
}
.fa-check-circle{
float: right;
position: relative;
line-height: 20px;
}