I am new in select2 js so please help me for selecting value according to given order. Means when i have to store value according to user decided order.
data = [{id:1, name:xyz},{id:2, name:abc},{id:3, name:lmn}]
Suppose I want to show id [1,2]
as selected but I am getting [2,1]
答案 0 :(得分:0)
添加此代码:
$('select').on('select2:select', function(e) {
var element = $(this).find('[value="' + e.params.data.id + '"]');
$(this).append(element);
$(this).trigger('change');
});
或者,
$("select").select2();
$("select").on("select2:select", function (evt) {
var element = evt.params.data.element;
var $element = $(element);
$element.detach();
$(this).append($element);
$(this).trigger("change");
});