Navigating a JSON

2

I want to take the information of this json ( link ) and show them in an HTML and show me only the data of the team that it has as clantag TRCIO, until now I have managed to show me the data, but it shows me those of all the equipment. How could I do to show me only those of that particular?

$(document).ready(function () {
    cargarDatos();
});
function cargarDatos() {
    var listaWot = "";
    $.ajax({
        url: 'https://wotclans.com.br/api',
        dataType: 'json',
        type: 'GET'

    }).done(function (response) {
        listaWot = "";
        listaWot += "<div class='card-panel'>";
        listaWot += "<table>";
        listaWot += "<tr>";
        listaWot += "<td class='tabName'>";
        listaWot += "Posición";
        listaWot += "</td>";
        listaWot += "<td class='tabName'>";
        listaWot += "Nombre";
        listaWot += "</td>";
        listaWot += "<td class='tabName'>";
        listaWot += "Puntuación";
        listaWot += "</td>";
        listaWot += "<td class='tabName'>";
        listaWot += "Ratio De Victorias";
        listaWot += "</td>";
        listaWot += "<td class='tabName1'>";
        listaWot += "Miembros Activos";
        listaWot += "</td>";
        listaWot += "</tr>";
        $.each(response.Clans, function (i, info) {
            listaWot += "<tr>";
            listaWot += "<td class='textCenter'>";
            listaWot += info.Item1;
            listaWot += "</td>";
            listaWot += "<td>";
            listaWot += info.Item2.Name;
            listaWot += "</td>";
            listaWot += "<td>";
            listaWot += info.Item2.TotalBattles;
            listaWot += "</td>";
            listaWot += "<td>";
            listaWot += info.Item2.TotalWinRate;
            listaWot += "</td>";
            listaWot += "<td class='textCenter'>";
            listaWot += info.Item2.Active;
            listaWot += "</td>";
            listaWot += "</tr>";
        });
        listaWot += "</table>";
        $("#wot").html(listaWot);
    });
}
    
asked by Danny Fox 05.10.2016 в 15:38
source

1 answer

3

In this part of the code you are going through all the clans showing the information:

    $.each(response.Clans, function (i, info) {
        listaWot += "<tr>";
        listaWot += "<td class='textCenter'>";
        listaWot += info.Item1;
        listaWot += "</td>";
        listaWot += "<td>";
        listaWot += info.Item2.Name;
        listaWot += "</td>";
        listaWot += "<td>";
        listaWot += info.Item2.TotalBattles;
        listaWot += "</td>";
        listaWot += "<td>";
        listaWot += info.Item2.TotalWinRate;
        listaWot += "</td>";
        listaWot += "<td class='textCenter'>";
        listaWot += info.Item2.Active;
        listaWot += "</td>";
        listaWot += "</tr>";
    });

As there is no restriction whatsoever, all that information of all the clans will be displayed. If what you want is to only show the information of the clans TRCIO (the name is in ClanTag ), all you have to do is add a check to make sure that this is the clan:

    $.each(response.Clans, function (i, info) {
        if (info.Item2.ClanTag == "TRCIO") {
            listaWot += "<tr>";
            listaWot += "<td class='textCenter'>";
            listaWot += info.Item1;
            listaWot += "</td>";
            listaWot += "<td>";
            listaWot += info.Item2.Name;
            listaWot += "</td>";
            listaWot += "<td>";
            listaWot += info.Item2.TotalBattles;
            listaWot += "</td>";
            listaWot += "<td>";
            listaWot += info.Item2.TotalWinRate;
            listaWot += "</td>";
            listaWot += "<td class='textCenter'>";
            listaWot += info.Item2.Active;
            listaWot += "</td>";
            listaWot += "</tr>";
        }
    });
    
answered by 05.10.2016 / 15:58
source