html - Select2 formatResult get attributes of option -


get custom data-attribute in select2 <select>

we need same thing specified in above link. but, how attributes of option element in formatresult function?

you try following code :

  $select2.data('placeholder', 'please choose').html(_options).select2({                     formatnomatches: function (term) {                         return 'there no "' + term + '" item';                     },                     formatresult: function(term) {                         return $(term.element).data('cnt');                     },                     allowclear: true   }); 

jsbin


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -