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

159
Visualizações
VueJS & Algolia: Rename items in ais-refinement-list (VueInstantSearch)

I want to change the item names of my search filters in the front end and I found that when using:

<ais-refinement-list [..] :transform-items="transformItems" />
</ais-refinement-list>

I can then redefine the lists labels in a method (Algolia docs):

transformItems: function(items) {
        
        return items.map(item => ({
          ...item,
          label: item.label.toLowerCase(),
        }));
        
      },

But what I need to do is rename all of the 6 filters/facets for the front end and I figured I need to do that with several if() statements. But how do I do that in this map()-method? For example how can I rename the item with label 'MC' to 'Multiple Choice'? I tried just writing

    transformItems: function(items) {
                
     return items.map(item => ({
     ...item,
    
     if(item.label == 'MC'){

            label: 'Multiple Choice',

        }else{

            label: item.label,
        }

    }));               
   },

But that failed spectacularly. What's the correct way to solve this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There surely is a better way but I solved it by outsourcing the if condition into another method called "rename(item.label)" where I give the changed label as return value and in the map() function I just say "label: rename(item.label),".

map function:

transformItems: function(items) {

        return items.map(item => ({
        ...item,

        label: this.rename(item.label),

        }));

   },

new rename method:

rename : function(label){

        // Rename MC to Multiple Choice
        if(label === 'MC'){
                label = 'Multiple Choice'
            }

      [..]      //other renaming if conditions

        return label

   },
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