使用 在 select2 中获取自定义数据属性 https://stackoverflow.com/questions/22261209/get-custom-data-attribute-in-select2-with-select
我们需要上面链接中指定的相同内容。但是,如何在formatResult函数中获取option元素的属性呢?
您可以尝试以下代码:
$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 http://jsbin.com/wicutoti/11/edit
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)