问题
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