0
Good morning guys, I am setting up a tree scheme (network) where I send the parameters via GET to my API, and it returns me the data to mount my code is as follows:
$('.btn-rede').click(function () {
let nivel = $(this).attr('data-nivel');
let pai = $(this).attr('data-pai');
console.log(nivel + ' ' + pai);
$.ajax({
url: HOME_URI + '/webservices/getRede',
type: 'GET',
data: {
pai: pai,
nivel: nivel,
},
headers: {
'token': '14f6d2b53b059116h23rs915e6329b6f19a3'
},
success: function(data) {
$.each(data, function (rede) {
$('#rede').append(`
<button class="btn btn-success btn-circle btn-md btn-rede" data-nivel="`+ data[rede]['nivel'] + `"data-pai="`+ data[rede]['cli_id'] + `">` + data[rede]['nivel'] + `</button>
<span> `+ data[rede]['cli_nome'] + `</span>
`);
});
}
});
});
On the side of my HTML I am mounting as follows:
<div class="row">
<div class="col-sm-12">
<div class="white-box">
<div class="col-md-12 text-center">
<button class="btn btn-success btn-circle btn-md btn-rede" data-pai="1" data-nivel="1"> 1</button>
<span> RCC Alimentos</span>
<div id="rede"></div>
</div>
</div>
</div>
</div>
That is my initial node, it will always be fixed, but all the others are dynamic, and are populated according to the response of my API and inserted in my #rede
. The way I’m putting it together he’s just doing the requisition and just looking for the data-pai="1"
and the data-nivel="2"
however, if I click a button that is level 2 it does not perform the search, someone has some idea of what might be?
Print of how you are returning me at the moment: https://prnt.sc/lrguiz NOTE: Level 2 nodes all have children but as I explained jQuery does not take the action of clicking the button to perform AJAX.
Wictor thank you so much! I hadn’t noticed this detail, and I needed to define an id to be the main one.
– Tiago Paza