3
I’m building Ivs dynamically via Javascript. I want to make its content display some information (usernames, emails, etc). The data is coming from the database in Json format.
The problem is that it does not display all participants. It displays only the first...
I’m riding that way:
$.each(value.participantes, function (index, item){
console.log(item);
html+= '<div id="infoUser" class="hide infoUser">'
+ '<div class="pull-left">'
+ '<img src="/resources/img/teste.jpg" class="foto-info-usuario" />'
+ '</div>'
+ '<div class="pull-right">'
+ '<div>'
+ '<i id="close" class="fa fa-times fa-lg pull-right closePopover"></i>'
+ '</div>'
+ '<div class="informacoes-user-texto">'
+ '<label class="nomeUser">'+item.nome_usuario+'</label>'
+ '<div class="fone-user">'
+ '<i class="fa fa-phone" aria-hidden="true"></i> '+item.fone_com+''
+ '</div>'
+ '<div class="email-user">'
+ '<i class="fa fa-envelope" aria-hidden="true"></i> '+item.login+''
+ '</div>'
+ '<div class="lista-tags wrap">'
+ '<div class="tags">'
+ '<div class="ribbon-top"></div>'
+ '<div class="ribbon-bottom"></div>'
+ '<label class="tags-user">Líder</label>'
+ '</div>'
+ '</div>'
+ '</div>'
+ '</div>'
+ '</div>';
});
The content of Json is this (console):
Object { nome_usuario="Albson Xavier", id_usuario=1786, login="[email protected]"}
Object { nome_usuario="Bruno Melo Pimentel", arquivo_foto="4.jpg", id_usuario=4, mais...}
Object { nome_usuario="Usuario Indefinido", id_usuario=1574, login="[email protected]"}
Object { nome_usuario="Albson Xavier", id_usuario=1786, login="[email protected]"}
Object { nome_usuario="Lucinéa Correia", id_usuario=1519, login="[email protected]"}
Object { nome_usuario="Albson Xavier", id_usuario=1786, login="[email protected]"}
Object { nome_usuario="Mere Magalhães", id_usuario=3, login="[email protected]"}
Object { nome_usuario="Albson Xavier", id_usuario=1786, login="[email protected]"}
Object { nome_usuario="Albson Xavier", id_usuario=1786, login="[email protected]"}
Object { nome_usuario="Vilanêz Brayner", arquivo_foto="5.jpg", id_usuario=5, mais...}
Object { nome_usuario="Cledson Lima", id_usuario=1, login="[email protected]"}
Object { nome_usuario="Marcos Moraes", id_usuario=2, login="[email protected]"}
Object { nome_usuario="Albson Xavier", id_usuario=1786, login="[email protected]"}
Object { nome_usuario="Anderson Souza", arquivo_foto="teste.jpg", id_usuario=1702, mais...}
Try to remove the "ids" from the HTML elements. This property has the purpose of being unique.
– Sorack
Could you make sure that 'html' is correct at the end of the loop? Could you post the rest of the code?
– Leonardo Lana
Yes, I’ve already made sure the html is correct. The problem is that it’s not just taking the first item of the json array. He can’t demand other users' names, for example... you know?
– André Albson
Try to remove the "ids" from the HTML elements. This property has the purpose of being unique
– Sorack
I did, but the problem remains.
– André Albson
You can make a Jsfiddle with your code so we can evaluate the problem? Or put the entire function of . js.
– Sorack
How are you rendering the 'html' variable' ?
– Leonardo Lana
By Jsfiddle it gets really bad. Better post all JS function.
– André Albson
You can put here the result of
JSON.stringify(value.participantes);
?– Sergio
https://jsfiddle.net/andrealbson/whbzupfd/
– André Albson
In the link above (jsfiddle), I put the whole JS function.
– André Albson
@Andréalbson tests like this: https://jsfiddle.net/whbzupfd/1/ works?
– Sergio
It did not work. Same error occurs
– André Albson
@Andréalbson can make a jsFiddle with the problem to happen live? otherwise it is difficult to have this question answer and be useful to someone else...
– Sergio
I tested your code, added some items, and it worked normally here: https://jsfiddle.net/eojfqk7u/
– Thales Chemenian