Generate Html second Json object

0

I need to receive a Json with the activity selection and generate the HTML according to this data.

I think it should look more or less like this, can anyone give me some tips to improve?

<script>
$(document).ready(function () {
    var CodigoMilestone = $("#CodigoMilestone");
    $.ajax({
        type: "GET",
        url: "/Dashboard/GetAtividades",
        sucess: function (atividades) {

            if (atividades != null) {
                $(atividades).each(function (i) {

                    var div = "<div> <table>";
                    var tr = "<tr>";
                    div +=
                    tr += "<td>" + atividades[i].InicioCedo;
                    tr += "<td>" + atividades[i].TempoRevisado;
                    tr += "<td>" + atividades[i].TerminoCedo;                        
                    div.append(tr);

                    tr += "<td>";
                    tr += "<td>" + atividades.Descricao;
                    tr += "<td>";
                    div.append(tr);

                    tr += "<td>" + atividades[i].InicioTarde;
                    tr += "<td>" + atividades[i].Folga;
                    tr += "<td>" + atividades[i].TerminoTarde;
                    div.append(tr);

                })
            }
        }
    })
});

Below a Json object:

[{"Codigo":7,"Descricao":"Atividade 1","CodigoMilestone":6,"TempoRevisado":2,"Inicio":"\/Date(1445738400000)\/","InicioCedo":"\/Date(1445738400000)\/","InicioTarde":"\/Date(-62135589600000)\/","TerminoCedo":"\/Date(1445911200000)\/","TerminoTarde":"\/Date(-62135589600000)\/","Ativo":true,"Milestone":null,"Dependencia":[],"Dependencia1":[]},{"Codigo":8,"Descricao":"Ativade 2","CodigoMilestone":6,"TempoRevisado":2,"Inicio":"\/Date(1445997600000)\/","InicioCedo":"\/Date(1445997600000)\/","InicioTarde":"\/Date(1445911200000)\/","TerminoCedo":"\/Date(1446084000000)\/","TerminoTarde":"\/Date(1446084000000)\/","Ativo":true,"Milestone":null,"Dependencia":[],"Dependencia1":[]}]

    
asked by anonymous 29.10.2015 / 23:01

1 answer

1

Your code has some errors like syntax of $ .each and the use of a jquery selector, let's go to the following example

Let's say you have a div with id content like this:

  <div id="conteudo"></div>

So I want to be able to put my information that is in an object called activities within that div.

 if (atividades != null) {
    var table = '';
    $.each(atividades,function (key,val) {
        table += '<table>';
        table += '<thead><tr><th>Código</th><th>Descrição</th></tr></thead>';
        table += '<tbody><tr><td>'+val.Codigo+'</td><td>'+ val.Descricao+'</td></tr></tbody>';
        table += '</table>'
    })
    $("#conteudo").append(table);
}

The validation ok, then I run the object by putting my values in a table, and after each I give an append.

See working at Jsfiddle

Now it's only you to work on your html and put the rest of your values in the table.

    
29.10.2015 / 23:46