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

87
Views
Filtering with a multi-select menu

So I have a select menu that lets the user select multiple options. the selected options correspond to actorModel. Then I have an object array and I wish to filter it according to the selected options. If the user selected option A and B , then it will return two objects from actorDocs. The one that has a label value 'A' and the one that has the label value 'B'. If no option is selected (actorModel is null) then it will return all objects from actorDocs.

The problem I am encountering in this code is that it only works if the user selects one option. If the user selects more than one, then I tink it is trying to locate an object that has several labels instead of several objects with each label.

Any help is more than welcome

const actorModel = ref({ 0:'label1', 1:'label2', 3:'label3'})
const actorDocs = ref([{'label':'label1'},{'label':'label2'},{'label':'label3'},{'label':'label4'}])

const actorListTest2 = computed(() => {
    if (actorModel.value == null){var ttt = actorDocs.value} 
    else { 

      var ttt = actorDocs.value.filter(obj => {
        return (
         (!actorModel.value.length || obj.label.includes(actorModel.value) )
       ) })}
    lenActordata.value = ttt.length
    return ttt
    });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try like following snippet:

const actorModel = {0:'label1', 1:'label3'}
const actorDocs = [{'label':'label1'}, {'label':'label2'}, {'label':'label3'}, {'label':'label4'}]

const actorListTest2 = () => {
  if (actorModel == null){
    return actorDocs
  } else { 
    return actorDocs.filter(obj => [...Object.values(actorModel)].includes(obj.label))
  }
};
console.log(actorListTest2())

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!