I've seen a lot examples of Select2
option tags set with "data-" attributes and I would like to do it.
I'm using ajax to get the data. I get the ID
and the TEXT
needed to build the select.
But how can I add more attributes to it?
I just didn't find the way to add them.
$(element).select2({
placeholder: 'Select one...',
width: '100%',
minimumInputLength: 2,
ajax: {
url: '/my/url',
dataType: 'json',
data: function(params) {
return {
q: params.term,
page: params.page
};
},
processResults: function(data, page) {
console.log(data);
return {
results: data
};
},
cache: true
}
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…