Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

88
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda