because they use the loop_start method?

1

hi what happens is that I do not understand why in some codes they use loop_start and loop_end to fill tables in html for example:

                <table class="table  table-hover">
                    <tr>
                        <td>Nombre del encuestador</td>
                        <td>Fecha de la encuesta</td>
                        <td>Nombre del predio del proyecto</td>
                        <td>Fecha/Hora inicio de grabación</td>
                        <td>Fecha/Hora última grabación</td>
                        <td>Estado</td>
                        <td>Municipio</td>
                    </tr>
                    <!--LOOP_START--> 
                        <tr>
                            <td>[#interviewer_name]</td>
                            <td>[#poll_date]</td>
                            <td>[#project_property_name]</td>
                            <td>[#recordStartDT]</td>
                            <td>[#recordEndDT]</td>
                            <td>[#state]</td>
                            <td>[#town_name]</td>
                        </tr>
                    <!--LOOP_END--> 
                </table>

please can you explain this method to me as well as how to implement it in javascript

    
asked by brahian.verac 08.02.2017 в 22:04
source

1 answer

0

It is to dynamically build the body of a table, for example:

I want to insert this data local_data=[2,3,4,5] in each row, I'll give you an example.

            var local_data=[2,3,4,5];
            var table=document.createElement('table');
            table.class="display";
            table.id="example";
            var thead=document.createElement('thead');
            var tr=document.createElement('tr');
            var th=document.createElement('th');
            var texto=document.createTextNode("hora");

            th.appendChild(texto);
            tr.appendChild(th);
            thead.appendChild(tr);
            table.appendChild(thead);
            var tbody=document.createElement('tbody');
            
            for(var indice=0; indice<local_data.length; indice++){//<!--LOOP_START--> 
                var tr=document.createElement('tr');
                var td=document.createElement('td');
                var datos=local_data[indice]; 
                var datoNodo = document.createTextNode(datos);
                td.appendChild(datoNodo);
                tr.appendChild(td);  
                tbody.appendChild(tr);
            }//<!--LOOP_END--> 

            
            table.appendChild(tbody);
            document.getElementById("tabla").appendChild(table);
<div id="ListaUsuarios"></div>
<div id="tabla"></div>
    
answered by 09.02.2017 / 03:10
source