简体   繁体   English

jQuery Selectric插件更新选项值问题

[英]Jquery selectric plugin update options values problems

i'm using jquery and jquery seletric plugin and it works fine but i need to refill options data after an ajax call. 我正在使用jquery和jquery seletric插件,它工作正常,但我需要在ajax调用后重新填充选项数据。

$('#mySelectID').empty();
     $.each(myResultAjaxObject, function(i, item) {
         $('#mySelectID').append($('<option>', {
             value: myValue,
             text: imyTextValue
         }));
     });
$('#mySelectID').selectpicker('refresh');

This code run for multiple drop-down list and it fills them correctly, the wrong thing is that mark as selected the first child of each drop-down list. 该代码针对多个下拉列表运行,并且正确填充了它们,这是错误的,即将每个下拉列表的第一个子项标记为选中。

Probably i'm missing something in the selectpicker update procedure. 可能我在selectpicker更新过程中缺少某些内容。

Any help would be appreciated. 任何帮助,将不胜感激。

Davide 达维德

try to set some delay and check: 尝试设置一些延迟并检查:

setTimeout(() => {
  jQuery('#mySelectID').selectpicker('refresh');
}, 500);

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

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