parse the below json with jquery and display data

2019-12-16 20:20发布

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 }

1条回答
狗以群分
2楼-- · 2019-12-16 20:38

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/

查看更多
登录 后发表回答