[Vuejs]-Nested array upto n child, set it for options

0👍

Try by using parent_id in data for adding - as:

<option v-for="category in categories" value="category.id"><span v-if="category.parent_id">{{getDash(parent_id)}}</span>{{category.name}}</option>

new Vue({
    ...
    computed: {
        getDash: function (parentId) {
          let string = '';
          for(let i = 0; i < parentId; i++) {
            string += '-'
          }
          return string;
        }
    }
    ...
})

Leave a comment