hello I try to generate a decision tree when the user chooses a reason option that generates the reasons and we create a select, if he clicks on an option and the API does not return an empty array another select below with sub-reasons which is created all this is dynamically created according to the response of the API as long as it does not return an empty array and so on
<template>
// the first select option don't generate
<select v-model="reasonOne" @change="eventOne(reasonOne)">
<option
v-for="(reason, key) in reasonsOne"
:key="key"
:value="reason.value"
:selected="reason.item === reasonOne"
@click="eventOne(reason.item)"
>
{{ reason.item }}
</option>
</select>
// the div with generate dynamically all select option
<div v-if="showSav">
<div id="select-pattern" class="step-two__select-wrapper" />
</div>
<template/>
<script>
async eventOne(option) {
let reasonsReturn = await customerApi.getReturnPattern(
app,
this.detailReturn.sku.product.id
);
if (!this.reasonsReturn.length) {
this.showSav = false;
}
let selectPattern = document.createElement('select');
let target = document.getElementById('select-pattern');
selectPattern.className = 'select-create';
selectPattern.id = 'create-input';
target.appendChild(selectPattern);
for (let item of reasonsReturn) {
let optionPattern = document.createElement('option');
optionPattern.value = item.id;
optionPattern.text = item.name;
selectPattern.appendChild(optionPattern);
}
document
.getElementById('create-input')
.addEventListener('change', async function () {
let reasonData = await customerApi.getReturnPattern(
app,
this.value
);
});
}
</script>
I was able to create the first select with it but the rest I am stuck I think we have to make a loop on select which will be created if the API returns data. i don't know how to do it while calling the api every time when the option changes