需要遍歷下面的JSON對象以生成報告(表結構中的表格報告)。在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重複的故事名稱並填充其他列各細節。
什麼是應該發生的重複?你想丟棄它們嗎?如果是的話,你想保留哪一個? – MCL
我們需要從重複條目中選擇任務名稱和狀態,並避免打印故事名稱以顯示兩次。 –