0

I would like to have a select with several levels

I wanted to use <optgroup> but this one cannot be selected so I found a solution on another post, put <option> by adding a space at the beginning to make the different levels.

<select>
    <option>select me</option>
    <option>&nbsp;me indented</option>
    <option>&nbsp;&nbsp;even more indentation</option>
</select>

Except I have to do it dynamically using a v-for.

<select v-model="form.contact.object" id="object">
    <option disabled value="null">Default text</option>
    <div v-for="(obj, i) in list" :key="i" :value="i">
        <option>{{ obj.list.label }}</option>
        <option v-for="(child, j) in obj.listChildren" :key="j" :value="j">&nbsp;{{ child.list.label }}</option>
     </div>
</select>

So I tried to use a div for my first loop but it doesn't work. The goal is to make a first for to retrieve the parent then a second for to retrieve the children

1 Answer 1

1

You should make something like this:

<select v-model="form.contact.object">
  <option disabled :value="null">Default text</option>
  <template v-for="(obj, i) in list" :key="'p_'+i">
    <option :value="'parent_'+i">{{ obj.listLabel }}</option>
    <option v-for="(child, j) in obj.listChildren" :key="'c_'+j" :value="'child_'+j" style="padding-left: 16px;">{{ child.listLabel }}</option>
  </template>
</select>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.