私の質問は簡単ですが、それを行う明確な例は見つかりませんでした。select に optgroup を追加し、jquery を使用してオプションを入力しようとしていますが、何らかの理由で機能しません。これは私のコードです:
$('#ptype').change(function() {
$.post(
"/sell/site/index/categories",
{
'parent_id': $('#ptype').val()
},
function(response){
var categories = $.parseJSON(response);
$('#sub_category').empty();
$.each(categories, function (index) {
var optgroup = $('<optgroup/>');
$.each(this.children, function (index) {
optgroup.add($("<option></option>")
.attr("value",index)
.text(this));
});
$("#sub_category").append(optgroup);
});
$("#sub_category").multiselect('refresh'); //refresh the select here
}
);
});
どんな助けでも大歓迎です!ありがとう!