[問題]jQuery.getJSON 的用法(已解決)
大大不好意思,小弟又遇到困難了 ...
json格式搞懂了,但在jquery該如何寫呢?
例如:
{
"column":["a","b","c"],
"data": [
{"a": "aaa", "b": "bbb", "c": "ccc" },
{"a": "aaaa", "b": "bbbb", "c":"cccc" },
{"a": "aaaaa", "b": "bbbbb", "c":"ccccc" }
]
}
該如何從jquery印出一個表格,首欄(TH)為「a、b、c」
第二欄開始(TD)為資料
用append()好像是一直加上去,會無法正常顯示
不知道要如何寫呢@_@
$(function(){
$.getJSON("data.php", function(json){
$("#content").html("<table><tr>");
for(var i=0;i<json.column.length;i++){
$("#content").append("<th>"+ json.column +"</th>");
}
$("#content").append("</tr><tr>");
for(var y=0;y<json.data.length;y++){
$("#content").append("<td>"+ json.data[y].a +"</td>");
$("#content").append("<td>"+ json.data[y].b +"</td>");
$("#content").append("<td>"+ json.data[y].c +"</td>");
}
$("#content").append("</tr></table>");
});
});
[ 本帖最後由 xxoxxoxxoxx 於 2009-10-23 14:10 編輯 ] |