我需要用jquery解析下面的json並在html表中顯示。用jquery解析下面的json並在html表中顯示數據
在html表中顯示「key」和「doc_count」的值。
幫助表示讚賞。見下文JSON:
{ 「鑰匙」: 「A」, 「計數」:100 }, { 「鍵」: 「AB」, 「計數」:800 }
我需要用jquery解析下面的json並在html表中顯示。用jquery解析下面的json並在html表中顯示數據
在html表中顯示「key」和「doc_count」的值。
幫助表示讚賞。見下文JSON:
{ 「鑰匙」: 「A」, 「計數」:100 }, { 「鍵」: 「AB」, 「計數」:800 }
試試此代碼:
使用任何模板引擎(Handlebars或Underscore)來處理HTML。我假設數據的形式是靜態Json。
做一個表,並追加到HTML頁面:
var Table=$("<table class='json_data'>");
$('body').append(Table);
然後遍歷整個JSON來獲得所需的value.Like這樣的:
$.each(parse_json.aggregations[2].buckets,function(index,value){
$('.json_data').append("<tr><td>"+value.key+"</td><td>"+value.doc_count+"</td></tr>");
})
的jsfiddle鏈接:https://jsfiddle.net/Dee0565/17u4xs3s/
謝謝john carpenter。 – user3570620
所以你爲此嘗試過嗎? –
查看datatables,這就是我使用的,它完美的作品 –
.aggregations.2.buckets不工作? – user3570620