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

207
Views
Filter records by multiple categories with Vuejs

I want to filter my JSON data by multiple categories in Vuejs. I'm using Vue 3 and collect.js.

Template:

<select v-model="selectedCategory" multiple>
    <option :value="null">Choose category</option>
    <option v-for="category in categories" :key="category.id" :value="category">{{ category.name }}</option>
</select>
<div v-for="project in filteredProjects" :key="project.id">
    <h6>{{ project.name }}</h6>
    <small>{{ project.category.name }}</small>
</div>

Script:

import collect from "collect.js";
export default {
    data() {
        return {
            projects: [{id: 1, name: "Lorem ipsum", category: {id: 1, name: "Website"}}, {id: 2, name: "Sit amet", category: {id: 2, name: "App"}}],
            categories: [{id: 1, name: "Website"}, {id: 2, name: "App"}],
            selectedCategory: null,
        };
    },
    computed: {
        filteredProjects() {
            let projects = this.projects;
            if (this.selectedCategory != null) {
                projects = projects.filter((project) => {
                    return collect(project.category).contains("id", this.selectedCategory.id);
                });
            }
            return projects;
        },
    },
};

Any suggestions?

Update: One project can also have multiple categories like this:

...
projects: [{id: 3, name: "Lorem ipsum dolor", category: {id: 1, name: "Website"},{id: 2, name: "App"}}],
...
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Found a solution:

this.selectedCategory.filter((category) => {
    projects = projects.filter((project) => {
        return collect(project.software).contains(
            "id",
            category.id
        );
    });
});
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!