Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

89
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda