2011-12-13 51 views
1

我創建了一個HTML表格如何動態地從JSON數組使用JQuery

<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> 

,這是我的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) 

從Java腳本IM提取添加數據到HTML表格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; 

我不想用我的Java腳本動態填充我的HTML數據表o JQuery和我對這兩種技術都很陌生。我不知道如何動態地填充表格。任何人都可以幫忙嗎?

+0

的可能的複製[轉換JSON陣列jQuery中的HTML表格(http://stackoverflow.com/questions/1051061/convert-json-array-to-an-html-table-in-jquery ) –

回答

1

關於此的基本知識如下,您只需將內容更改爲您的數據即可。

//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++; 
}