问题
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