【发布时间】:2015-07-22 20:00:45
【问题描述】:
HTML 代码
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script>
$(function() {
var dmJSON = "three.json";
$.getJSON( dmJSON, function(data) {
$.each(data.records, function(i, f) {
var tblRow = "<tr>" + "<td>" + f.Clue + "</td>" + "<td>" + f.Answer + "</td>" + "<td>" + f.Status + "</td>" + "<td> " + f.Views + "</td>" + "</tr>"
$(tblRow).appendTo("#entrydata tbody");
});
});
});
</script>
</head>
<body>
<div class="wrapper">
<div class="profile">
<table id= "entrydata" border="1">
<thead>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</body>
</html>
JSON 数据
{
"records": [
{
"Clue" : "First Clue",
"Answer" : "Answer to the first clue",
"Status" : "Rejected",
"Views" : "10"
},
{
"Clue" : "Second Clue",
"Answer" : "Answer to the second clue",
"Status" : "Rejected",
"Views" : "15"
},
{
"Clue" : "Third Clue",
"Answer" : "Answer to the third clue",
"Status" : "Rejected",
"Views" : "10"
},
{
"Clue" : "Fourth Clue",
"Answer" : "Answer to the fourth clue",
"Status" : "Rejected",
"Views" : "10"
},
{
"Clue" : "Fifth Clue",
"Answer" : "Answer to the fifth clue",
"Status" : "Rejected",
"Views" : "10"
},
{
"Clue" : "Sixth Clue",
"Answer" : "Answer to the sixth clue",
"Status" : "Rejected",
"Views" : "10"
},
{
"Clue" : "Seventh Clue",
"Answer" : "Answer to the seventh clue",
"Status" : "Rejected",
"Views" : "10"
},
{
"Clue" : "Eigth Clue",
"Answer" : "Answer to the eigth clue",
"Status" : "Rejected",
"Views" : "10"
},
{
"Clue" : "Nintht Clue",
"Answer" : "Answer to the ninth clue",
"Status" : "Rejected",
"Views" : "10"
}
]
}
从上面的代码中,JSON 数据存储在一个表中。我想将每条记录存储在不同的表中。有 8 条记录,所以我想要 8 个表,每个表有 1 条记录。 例如:在第一个表中,我希望存储第一条记录(即第一条线索,对第一条线索的回答,拒绝 10) 同样在第二个表中我想存储第二个记录。怎么做? 对此的任何解决方案将不胜感激。提前致谢
【问题讨论】:
标签: javascript html json