我希望能够ng-repeat
在前端解析我的响应。我在解析具有多个项目的响应而不是使用ng-repeat
列表的单个项目时遇到问题。
我能够解析;但我必须ng-repeat
在前端创建 2 个具有单独配置的不同列表,并添加一些丑陋的逻辑以在数组长度大于 1 时不显示。
我的目标是在我的部分中只有一个ng-repeat
元素,它可以处理两种响应或更好的方法来处理这个要求。
下面的详细解释和jsfiddle。
我想对两个 JSON 响应都使用这个 ng-repeat 设置。
<ul ng:repeat="report in reportConfigured.Reports">
<li ng:repeat="reportItem in report">{{reportItem.ReportName.$}}</li>
</ul>
以下是当有多个报告时我从我的网络服务获得的响应。
{
"Reports": {
"@xmlns": {
"$": "http:\/\/ws.wso2.org\/dataservice"
},
"Report": [{
"ReportID": {
"$": "20"
},
"ReportName": {
"@xmlns": {
"$": "null"
},
"$": "Examination Results"
},
"VisibleToPartner": {
"$": "false"
},
"ReportType": {
"@xmlns": {
"$": "null"
},
"$": "Examination Report"
},
"TemplateID": {
"$": "9"
}
}, {
"ReportID": {
"$": "163"
},
"ReportName": {
"@xmlns": {
"$": "null"
},
"$": "Scheduled Candidates with Test Center"
},
"VisibleToPartner": {
"$": "false"
},
"ReportType": {
"@xmlns": {
"$": "null"
},
"$": "Examination Report"
},
"TemplateID": {
"$": "220"
}
}, {
"ReportID": {
"$": "212"
},
"ReportName": {
"@xmlns": {
"$": "null"
},
"$": "Survey Report by Test"
},
"VisibleToPartner": {
"$": "false"
},
"ReportType": {
"@xmlns": {
"$": "null"
},
"$": "Examination Report"
},
"TemplateID": {
"$": "269"
}
}]
}
};
当只有一份报告时,我从我的服务中收到此响应
{
"Reports": {
"@xmlns": {
"$": "http:\/\/ws.wso2.org\/dataservice"
},
"Report": {
"ReportID": {
"$": "212"
},
"ReportName": {
"@xmlns": {
"$": "null"
},
"$": "Survey Report by Test"
},
"VisibleToPartner": {
"$": "true"
},
"ReportType": {
"@xmlns": {
"$": "null"
},
"$": "Examination Report"
},
"TemplateID": {
"$": "269"
}
}
}
}
我希望能够用相同的ng-repeat
. 我附上了一个 jsfiddle 以获取更多详细信息。