I have saved data in the database and want to load it as selected in the Select2 field on page load.
What I`ve tried is this(whit example data):
productsSelect.select2('val', [{'id':1,'text':'lala'},{'id':2,'text':'blabla'}])
I simply can't find such option in the documentation or I can't understand it probably. My select2 looks like:
const productsSelect = $("#benefitProductsSelect")
productsSelect.select2({
minimumInputLength: 4,
multiple: true,
ajax: {
url: "/admin/Products/getAllSelect2",
dataType: "json",
processResults: function (data) {
return { results: data.items }
}
}
})
E.g. something liek selectedValues
option. Is there such opportunity?
question from:
https://stackoverflow.com/questions/65830324/how-to-set-selected-values-in-ajax-multi-select2 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…