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

134
Visualizações
HTML value store list of dictionary

I am trying to loop through an array of objects stored in the value-media attribute of my button.

I'm able to get data from value-media and show it, but I can't loop through this data - it treats it like one long string (I'm guessing) and showing "undefined"

var medias = [button.getAttribute('value-media')]
console.log(medias)

$.each(medias, function(index, value) {
  alert(value.id);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<button type="submit" id="editUserBtn" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#editUser" value-userid="34" value-username="CUSTOMER1_TEST2" value-media="[{'id': '50', 'name': 'CUSTOMER1_Windows Notification', 'sendto': ['test@test.com', 'test2@test.com']}, {'id': '51', 'name': 'CUSTOMER1_ALL', 'sendto': ['test@test.com', 'test2@test.com']}]">
  <img src="/static/images/settings_black_24dp.svg" title="Edit user"/>
</button>

Could you help me to make it working? I need to go throught this data and for each dictionary in list take ID :(

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

0

Thank you! It's working now. Here is the solution:

var medias = $(button).data('media')
var mediasJSON = JSON.parse(medias.replace(/\'/g, "\""))
    $.each(mediasJSON, function(index, value) {
        alert(value.name + value.id)
      });

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