Selectizejs isn't loading the options correctly

China☆狼群 提交于 2020-01-16 18:50:14

问题


I'm using ajax, creating a dependent category and subcategory, everything works, my html is valid, I'm using selectizejs on both category and sub category. the category is working fine, the subcategory isn't. If I don't use selectize, everything works perfectly

 $(".category").change(function () {
     var id = $(this).val();
     var dataString = 'id=' + id;

     $.ajax
         ({
             type: "POST",
             url: "subcat.php",
             data: dataString,
             cache: false,
             success: function (html) {
                 $(".subcat").html(html);
             }
         });
 });
$('#subcat').selectize({
    plugins: ['remove_button'],
    persist: false,
});

index.php

<label class="control-label col-md-3 col-3">Sub Category <span class="required">*</span>
<select name="post[subcategory]" class="subcat" id="subcat">
<option selected="selected" value="">Select Sub Category</option>
</select> </label>

subcat.php

foreach ($children as $child) {?>
<option value="<?php echo $child->id; ?>"><?php echo $child->name; ?></option>
<? } ?>

No errors in console. When you select a category then all the sub categories gets displayed in the browser as static text without the possibility of selecting an option.

Again, if I remove selectize, I get a perfectly normal dropdown.

来源:https://stackoverflow.com/questions/49158849/selectizejs-isnt-loading-the-options-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!