Select2 formatResult get attributes of option

笑着哭i 提交于 2019-12-13 16:44:18

问题


Get custom data-attribute in select2 with <select>

We need the same thing specified in the above link. But, how to get the attributes of option element in formatResult function?


回答1:


You could try the following code :

  $select2.data('placeholder', 'please choose').html(_options).select2({
                    formatNoMatches: function (term) {
                        return 'There is no "' + term + '" item';
                    },
                    formatResult: function(term) {
                        return $(term.element).data('cnt');
                    },
                    allowClear: true
  });

JSBIN



来源:https://stackoverflow.com/questions/23179611/select2-formatresult-get-attributes-of-option

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!