Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
Filter nested v-for list
<div>
    <q-card              
        v-for="box in boxes"
        :key="box.id">
        <q-item>
            <q-item-section>
                <span> {{ box.name }} </span>
            </q-item-section>
        </q-item>

        <q-list>
            <q-item
                v-for="tool in box.tools"
                :key="tool.id"
                clickable
                <q-item-section>
                    <span> {{ tool.name }} </span>
                </q-item-section>            
            </q-item>
        </q-list>
    </q-card>
</div>

Form input filter value

inputFilterValue = "box A"

Filter boxes

Edited with return.

computed: {
    boxes(){
      return boxes.filter(box => {
            return box.name.toLowerCase().match(inputFilterValue.toLowerCase())
        });
    }
}

This works

How to filter too nested v-for box-tools list?

EDITED:

CODEPEN: https://codepen.io/ijose/pen/NWyoRMX

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

In the filter callback of boxes add a condition if the tool name matches the inputFilterValue

computed: {
    boxes(){
        return boxes.filter(box => {
          return box.name.toLowerCase().match(inputFilterValue.toLowerCase()) ||
            box.tools.filter(tool=>tool.name.toLowerCase().match(inputFilterValue.toLowerCase())
        });
    }
}
about 4 years ago · Juan Pablo Isaza Report

0

You can use JavaScript filter() along with some() method. some() method checks if any of the elements in an array pass the function.

Demo :

new Vue({
  el: '#app',
  data: {
    value: null,
    boxes: [],
    dataObj: [{
      id: 1,
      name: 'Box A',
      tools: [{
        id: 1,
        name: 'Tool A'
      }, {
        id: 2,
        name: 'Tool D2'
      }]
    }, {
      id: 2,
      name: 'Box B',
      tools: [{
        id: 1,
        name: 'Tool B'
      }]
    }, {
      id: 3,
      name: 'Box C',
      tools: [{
        id: 1,
        name: 'Tool C'
      }]
    }]
  },
  mounted() {
    this.boxes = structuredClone(this.dataObj);
  },
  methods: {
    inputFilterValue(filterField) {
      if (filterField === 'box') {
        this.boxes = this.dataObj.filter(box => box.name.toLowerCase().match(this.value.toLowerCase()))
      } else {
        const filteredToolsArr = this.dataObj.map(box => {
          const filteredTool = box.tools.filter((
            { name }) => name.toLowerCase().match(this.value.toLowerCase()));
            return { ...box, tools: filteredTool }
        })
        this.boxes = filteredToolsArr.filter(obj => obj.tools.length);
      }
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  Filter : <input type="text" v-model="value" @keyup="inputFilterValue('tool')"/>
  <ul v-for="box in boxes" :key="box.id">
    <li>{{ box.name }}</li>
    <ul v-for="tool in box.tools" :key="tool.id">
      <li>{{ tool.name }}</li>
    </ul>
  </ul>
</div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!