简体   繁体   中英

How to add a data dynamically from JSON array to HTML table using JQuery

I have created a HTML table

<table id="top_five_table">
 <tr>
 <td> </th>
 <th>URL</th>
 <th width="90">Total Hits</th>
 <th width="380">Percentage of all Hits</th>
 </tr>

 <tr>
 <td></td>
 <td></td>
 <td></td>
 <td></td>
 </tr>              
</table>

and this is my json object array

json_object = None
json_object = {'url_name': url_name, 'total_count': entity.total,\
'url_id': url_id,
'percentage': percentage, 'facebook_count': entity.facebook_count,\
'twitter_count': entity.twitter_count, \
'buzz_count': entity.buzz_count, \
'linkedin_count': entity.linkedin_count, \
'digg_count': entity.digg_count,\
'delicious_count': entity.delicious_count,\
'reddit_count': entity.reddit_count}
json_array.append(json_object)

from a java script im extracting the json object as follows

var json_array = data.json_array;
var table = document.getElementById('top_five_table');
var rowCount = table.rows.length;
var colCount = table.rows[0].cells.length;

I wont to populate my HTML Data table dynamically using Java script or JQuery and im so new to these two technologies. I do not know how populate the table dynamically . Can any one help?

The basics off this is below you will just need to change content to your data.

    //EQ The row off the table
    var row = $("#top_five_table tr").eq(1);

var i=0;
while (i<=3){
    //EQThe col off the table
        var col = $(row).find("td").eq(i).html("content");
i++;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM