[英]How to add an image in Select2 options?
I have a select: 我有一个选择:
<select data-bind="options : PeriodeOptions, optionsValue : 'Periode',
optionsText : function(item) { return AddLock(item)}" id="SelectPeriode"></select>
And I have my fucntion; 我有我的功夫;
//am - Fonction permettant d'ajouter le cadenas à côté de la Periode si elle est cloturée
function AddLock(pItem) {
if (!pItem.IsCloturePeriode)
return pItem.Periode;
var lTemplate = $('<span>' + pItem.Periode + '<img src="/Ressources/Images/Locked.png"/></span>');
return lTemplate;
};
I'm not sure if the question is tagged incorrectly, but i don't see your select2 function in the code youve given 我不确定问题是否标记错误,但我没有在您给出的代码中看到您的select2函数
however here is a sample of select2 templating code that would use images in the select and the result 但是这里有一个select2模板代码示例,它将使用select和result中的图像
function formatData (data) {
if (!data.id) { return data.text; }
var $result= $(
'<span><img src="/Ressources/Images/Locked.png"/> ' + data.text + '</span>'
);
return $result;
};
$("#SelectPeriode").select2({
templateResult: formatData,
templateSelection: formatData
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.