2015-09-29 6 views
5

मैं एक का चयन किया है:
चयन 2 विकल्पों में कोई छवि कैसे जोड़ें?

<select data-bind="options : PeriodeOptions, optionsValue : 'Periode', 
optionsText : function(item) { return AddLock(item)}" id="SelectPeriode"></select> 


और मैं अपने 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; 
     }; 


यह मुझे एक वस्तु भेजता है: enter image description here
कृपया मदद!

उत्तर

5

मुझे यकीन है कि अगर सवाल गलत तरीके से टैग किया गया है नहीं कर रहा हूँ, लेकिन मैं कोड youve लेकिन यहाँ

दी अपनी Select2 समारोह नहीं दिख रहा है Select2 templating कोड का एक नमूना है कि चयन में छवियों का उपयोग होता है और परिणाम

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 

}); 
+0

हाँ मेरे पास एक चयन 2 फ़ंक्शन है, यह कोड में नहीं दिखाया गया है। मुझे वास्तव में समाधान मिला, यह आपके लिए अनुकरणीय है, लेकिन मुझे आपकी पसंद है। मैंने किया: '<डेटा-बाइंड = = विकल्प का चयन करें: पेरीओडऑप्शन, विकल्प वैल्यू:' पेरीओड '' आईडी = "सिलेक्टिओरोड"> '- मैंने विकल्प और विकल्प छोड़ा (हटाया विकल्प टेक्स्ट)। और templateResult और templateSelection में मैंने किया था: 'समारोह (आइटम) { वर lTemplate = $ ( '' + item.text + '' ); वापसी lTemplate; }, ' –

संबंधित मुद्दे