需要遍历以下 JSON 对象以生成报告(表格结构中的表格报告)。
报告将基本上由故事列表及其相关任务状态组成。
QueryResults = {
"Results": [
{
"Name" : "Tech Design",
"State" : "Completed",
"StoryName" : "FB Integration"
},
{
"Name" : "Development",
"State" : "In-Progress",
"StoryName" : "FB Integration"
},
{
"Name" : "QA Testing",
"State" : "Not Started",
"StoryName" : "FB Integration"
},
{
"Name" : "Front End Development",
"State" : "Completed",
"StoryName" : "FB Integration"
},
{
"Name" : "Tech Design",
"State" : "Not Started",
"StoryName" : "Twitter Integration"
},
{
"Name" : "Development",
"State" : "Not Started",
"StoryName" : "Twitter Integration"
}
]
}
要填充的 HTML:
<table>
<tr>
<td>StoryName</td>
<td>TechDesign</td>
<td>FED</td>
<td>QA</td>
<td>Development</td>
</tr>
<tr>
<td>FB Integration</td>
<td>Completed</td>
<td>Completed</td>
<td>In-Progress</td>
<td>In-Progress</td>
</tr>
......
......
</table>
脚本 :
for(var i=0; i < QueryResults.Results.length; i++) {
data+= '<tr><td>' + QueryResults.Results[i].StoryName + '</td><td>' + QueryResults.Results[i].State + '</td></tr>';
}
// it will list down all the story name i.e. same story name multiple times
请在迭代 JSON 并在其他列中填充相应的详细信息时为我提供删除重复故事名称的指针。