This is working fine with brave but in chrome only some options are populated and most are missing.
Im fetching with jquery and i want to populate the data in an hierarchical manner based on the component_code and parent_component_code.
$.ajax({
type: "get",
url: "/get-components/" + code,
success: function (response) {
let data = response;
const createSelectOptions = (data, parentCode) => {
const options = [];
$.each(data, (index, item) => {
if (item.parent_component_code === parentCode) {
if (
data.some(
(child) =>
child.parent_component_code ===
item.component_code
)
) {
options.push(
`<optgroup label="${item.component_desc}">`
);
options.push(
...createSelectOptions(
data,
item.component_code
)
);
options.push(`</optgroup>`);
} else {
options.push(
`<option value="${item.component_code}">${item.component_desc}</option>`
);
}
}
});
return options;
};
const selectOptions = createSelectOptions(data, null);
$("#component_code").html(
[
`<option value="" selected disabled>--Select Component--</option>`,
...selectOptions,
].join("")
);
$("#component_code").prop("disabled", false);
},
});