简体   繁体   中英

Select2 failed load selected item

I'm using select2 plugin for PHP programs,

I got sometimes I can load the value with this way

$('#item_codePop').val(itemCodePop);
$("#item_codePop").trigger('change');

But, that only works for a data from add function and it not work when I get the data from load function.

at my add function, I always call this

$('#item_codePop').val('');
$("#item_codePop").trigger('change');

that's the only different between Edit data from add function and the load function. Is that impact something ?

I think you must create variable for your object like following and then trigger change on it...

var $example = $(".your_Class").select2();

$(".your_button").on("click", function () {
      $("#item_codePop").val("").trigger("change");
})

visit this link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM