How to render html in select2 options

后端 未结 5 966
傲寒
傲寒 2020-12-25 10:46

In this example of data loaded from a remote source I can see images and other html elements rendered as options. I\'d like to accomplish the same thing using data in a loc

5条回答
  •  时光取名叫无心
    2020-12-25 11:19

    If I am not mistaken you can only render HTML if you set the templateResult and templateSelection options and have them return a jQuery object.

    var data = [
          { id: 0, text: '
    enhancement
    ' }, { id: 1, text: '
    bug
    This is some small text on a new line
    ' }]; $("select").select2({ data: data, templateResult: function (d) { return $(d.text); }, templateSelection: function (d) { return $(d.text); }, })
        
        
        
    
        
     

提交回复
热议问题