0
For each card registered, I redirect the user to his card view page and I list all the cards he has already registered.
Every card has its nome
, then for each card I create the layout
and insert the nome
. So far so good.
I’m doing it this way:
tx.executeSql('SELECT empresa FROM cartoes', [], function(tx, results){
for (var i=0; i<results.rows.length; i++) {
var nomes = results.rows.item(i);
cartoesCadastrados(); //essa função cria o layout
console.log(Object.values(nomes));
$('.row').find('span').text(Object.values(nomes));
}
That one console.log(Object.values(nomes));
me returns the names of the cards already registered:
["Ebcard"]
["Claro"]
["Itaú"]
This is where the problem lives:
$('.row').find('span').text(Object.values(nomes));
My intention in this code above is that for each layout
should insert its nome
. The problem is that it inserts the same name for all, the last that was registered, in this case, the 3 registered cards are with the nome
of Itaú
.
Does anyone know what it can be?
The layout of the registered card is like this:
<html>
<div class="container">
<div class="row">
<!-- onde vai plotar o template -->
<div id="container"></div>
</div>
</div>
<template>
<div class="row" id="corpo-cartoes">
<div class="col s12 m7" style="width: 100%;">
<div class="card">
<div class="card-image">
<img src="img/apresentacao.jpg">
<span class="card-title">Card Title</span>
</div>
<div class="card-action icone-meu-cartao">
<a href="#" ><i class="material-icons">code</i></a>
<a href="#"><i class="material-icons">crop_free</i></a>
<a href="#"><i class="material-icons">visibility</i></a>
<a href="#"><i class="material-icons btn-editar">edit</i></a>
</div>
</div>
</div>
</div>
</template>
</html>
<script>
function cartoesCadastrados() {
var content = document.querySelector('template').content;
document.querySelector('#container').appendChild(
document.importNode(content, true));
}
</script>
I believe that if
Object.values(nomes)
returns an array, so you would need to doObject.values(nomes)[i]
to take each of the array values, no?– Máttheus Spoo
I’ve tried and it doesn’t work. So he fills only the first.
– user125347
The strange thing is that if I put console.log(Object.values(names)[i]); it returns only the first registered name, and the rest comes as Undefined.
– user125347
$('.row').find('span').text(Object.values(nomes[i]));
doesn’t work?– Jorge.M