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;
};
It sends me an object:
Please help!
I'm not sure if the question is tagged incorrectly, but i don't see your select2 function in the code youve given
however here is a sample of select2 templating code that would use images in the select and the 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
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With