简体   繁体   English

Select2失败加载所选项目

[英]Select2 failed load selected item

I'm using select2 plugin for PHP programs, 我正在将select2插件用于PHP程序,

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. 但是,这仅适用于add功能中的数据,而当我从load功能获取数据时则无效。

at my add function, I always call this 在我的add函数中,我总是称其为

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

that's the only different between Edit data from add function and the load function. 这是从add功能编辑数据和load功能之间的唯一区别。 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 访问此链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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