如何在Select2选项中添加图像? [英] How to add an image in Select2 options?

查看:109
本文介绍了如何在Select2选项中添加图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个选择:

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;
        };


它向我发送一个对象: < br>请帮帮忙!


It sends me an object:
Please help!

推荐答案

我不确定问题标记是否错误,但我看不到你的select2你给出的代码中的函数

I'm not sure if the question is tagged incorrectly, but i don't see your select2 function in the code youve given

但是这里有一个select2模板代码示例,它将使用select和结果中的图像

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

});

这篇关于如何在Select2选项中添加图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆