用jquery解析下面的json,并在html表中显示数据 [英] parse the below json with jquery and display data in a html table
问题描述
在html表格中显示key和doc_count的值。
使用jquery解析下面的json并显示在html表格中。
帮助表示感谢。请参阅下面的json:
$ {
key:A,
count:100
},
{
key:AB,
count:800
}
试试这段代码:
使用任何模板引擎(把手或下划线)来处理HTML。
制作表格并追加到HTML页面:
<$>我假设数据的格式为Static Json。 p $ p>
var Table = $(< table class ='json_data'>);
$('body')。append(Table);
然后迭代整个Json以获得期望值。像这样:
$。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/
I need to parse the below json with jquery and display in a html table.
display the values of "key" and "doc_count" in a html table.
Help is appreciated. see json below:
{ "key": "A", "count": 100 }, { "key": "AB", "count": 800 }
Try This code:
Use any Template Engine(Handlebars or Underscore) to process HTML. I am assuming data is in the form of Static Json.
Make a table and append to HTML page:
var Table=$("<table class='json_data'>");
$('body').append(Table);
Then iterate whole Json to get the desired value.Like this:
$.each(parse_json.aggregations[2].buckets,function(index,value){
$('.json_data').append("<tr><td>"+value.key+"</td><td>"+value.doc_count+"</td></tr>");
})
JSFiddle Link: https://jsfiddle.net/Dee0565/17u4xs3s/
这篇关于用jquery解析下面的json,并在html表中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!