1
I’m getting a json with a collection of objs, the quantity is dynamic, I’m creating the div element and added a dynamic id to it, my idea was to make div.setAttribute("onclick", alert("${idRotativo}")) but Vue does not find the function alert when I do so,
I also made :
div.setAttribute("@click", alerta("${idRotativo}")
)
but of that mistake:
With:
div.setAttribute("v-on:click", alerta("${idRotativo}")
)
No error and it can set the attribute "v-on:click", but does not work.
I made an ex of what I need in jsFiddle When you click on the row it returns the id of the clicked element, https://jsfiddle.net/CarlosAlexandreleutz/a89m4r7d/6/
I thought it might be like I was creating the html element that is printed on the screen
then tried with Document.createelement('div');
var conter = 0;
function verificaRelacionamento (element){
conter++
let elemento = element;
let div = document.createElement('div');
div.textContent = `Id: ${elemento.id} Descrição: ${elemento.descricao} Descrição do pai ${elemento.descricaoPai}`;
let idRotativo = 'teste' + conter;
div.setAttribute("id", idRotativo)
div.setAttribute("v-on:click", `alerta("${idRotativo}")`)
let paiDeTodo = document.getElementById('paiDeTodos');
paiDeTodo.appendChild(div)
}
function tamanhoDoArray(a){
let array = a;
array.forEach(verificaRelacionamento)
}
function alerta(a){
alert(a)
}
And with a string template:
var conter = 0;
var html = '';
function verificaRelacionamento(element) {
conter++
let elemento = element;
html += `<div v-on:click="alerta('colapser-${conter}')" class="colapser-${conter}">
Id: ${elemento.id} Descrição: ${elemento.descricao} Descrição do pai ${elemento.descricaoPai}
<button v-on:click="alerta('colapser-${conter}')">teste</button>
</div>`;
document.getElementById("paiDeTodos").innerHTML = html;
}
function tamanhoDoArray(a){
let array = a;
array.forEach(verificaRelacionamento)
}
function alerta(a){
alert(a)
}
the 2 generate the same html, but nothing happens when I click on them
my final goal and make an account plan, I will use this id to add and remove a class to collapse the items, msm the way it has in the google inspection, that the user can click the arrow and go seeing what is inside the elements,
NOTE: if I copy the generated element in the browser and paste it into html, it works