简体   繁体   English

如何使用JQuery将数据从JSON数组动态添加到HTML表

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

I have created a HTML table 我创建了一个HTML表

<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对象数组

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 从Java脚本im提取json对象,如下所示

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. 我不会使用Java脚本或JQuery来动态填充HTML数据表,而这对这两种技术还是很新的。 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++;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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