在我的項目中,我通過GET請求獲得了JSON響應。 subTopics將由用戶選擇並存儲。之後,我使用所選的ID向服務器發送POST請求。在使用ng-repeat中的另一個對象時訪問對象屬性
例JSON1:(來自GET請求)
{
"TopicList" :
[{
"id": "1234",
"name": "topic1",
"number": "1",
"subTopics": [
{
"id": "4567",
"name": "subTopic1.1",
"number": "1.1"
},
{
"id": "9876",
"name": "subTopic1.2",
"number": :1.2"
}
]
}]
}
在POST響應我從服務器獲取,這我在我的HTML視圖作爲一個表以顯示另一個JSON對象。在響應JSON中,我有subTopics id(由用戶選擇),但我沒有與id關聯的subTopic名稱。
我必須在我的表中顯示subTopic名稱,這是在一個單獨的對象中可用(見上面的JSON文件)。我不知道如何在使用另一個JSON對象時訪問第一個JSON對象。
我的表視圖看起來像這樣,
<tr ng-repeat-start="tableRow in searchCtrl.tableViewData" ng-click="tableRow.expanded = !tableRow.expanded">
<td>{{tableRow.project.name}}</td>
<td>{{tableRow.project.number}}</td>
<td>{{tableRow.project.endDate | date}}</td>
<td>{{tableRow.topicIds[0]}}</td>
<td>{{tableRow.matching.score}}</td>
</tr>
正如你所看到的第4行:<td>{{tableRow.topicIds[0]}}</td>
顯示的ID。我如何顯示topicName?
任何幫助將是可觀的。
EDIT
以我控制器此變量包含上述JSON對象。
if (!self.topic) {
searchService.getTopic().then(
function (response) {
self.topic = response.data;
},
function (error) {
alert("Server is not found");
}
);
}
因此,主題變量包含響應JSON對象。也許它會有所幫助。
@csbarnes:感謝你使問題更容易理解... + 1個 –