jQuery函数使用JSON数据创建表 [英] jQuery function to create table using JSON data

查看:106
本文介绍了jQuery函数使用JSON数据创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jQuery从本地文件中检索JSON对象并将其显示在表中?这是JSON文件(jsondata.json)的内容:

How do you retrieve a JSON object from a local file and display it in a table using jQuery? Here is the content of JSON file (jsondata.json):

{
"scores" : [ ["3/1/2011", 610],["4/1/2011", 610],["5/1/2011", 610],["6/1/2011", 610], ["7/1/2011", 720], ["8/1/2011", 500], ["9/1/2011", 500] ]
}

推荐答案

示例-演示 http://jsfiddle.net /kVdZG/

您可以迭代并附加元素.

You can iterate and append the elements.

<table id='scores' border="1"></table>  

JS-

var data = { "scores" : [ ["3/1/2011", 610],["4/1/2011", 610],["5/1/2011", 610],["6/1/2011", 610], ["7/1/2011", 720], ["8/1/2011", 500], ["9/1/2011", 500] ] }


$(data.scores).each(function(index, element){  
     $('#scores').append('<tr><td> '+element[0]+' </td> <td> '+element[1]+' </td></tr>');       
})

这篇关于jQuery函数使用JSON数据创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆