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

420
Visualizações
If repeater field contains value (how to get the array?)

I have a table #mytable with a column

<table id="#mytable">
<tr><td class="name">John</td></tr>
<tr><td class="name">Paul</td></tr>
<tr><td class="name">Mary</td></tr>
</table>

I want to add a class to if the name is contained in an array. So I did the following :

 jQuery.each($('#mytable .name'), function () {
        var line = $(this).closest("tr");
        var name = this.textContent;
 
    if (['David','Paul','Melissa'].includes(name)) {
      line.addClass("yes");
    }       
  });

This works fine, the class .yes will be added to the 2nd line, the one containing Paul.

However, my problem is when trying to get the actual array. The values are contained in a repeater subfield. So i added a variable and tried to replace the array by my variable :

 jQuery.each($('#mytable .name'), function () {
        var line = $(this).closest("tr");
        var name = this.textContent;
var repeaternames = $('#myrepeater .names .acf-input .select2-selection__rendered');
 
    if (repeaternames.includes(name)) {
      line.addClass("yes");
    }       
  });

But this doesn't work. Is it a syntax issue, is it because my "repeaternames" variable is not an actual array ?

Or because I'm not getting the right values? As you can see, the repeater values that I'm trying to get are in a select2 select field, and maybe i'm not targeting the right elements.

Thank you in advance for your help !!

about 4 years ago · Juan Pablo Isaza
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