【发布时间】:2015-02-09 08:00:46
【问题描述】:
我正在使用 AngularJS 显示来自 JSON 的带有参考 ID 的数据。但是 JSON 结构略有改变,所以参考 id 没有正确。
以前的 JSON:
{
"tid": "2440",
"name": "Alfredo's Pizzeria",
"field_location_category": [
"Food and Dining"
]
},
{
"tid": "2441",
"name": "Allegro Dining Room",
"field_location_category": [
"Food and Dining"
]
},
{
"tid": "2443",
"name": "Art Gallery",
"field_location_category": [
"Gifts & Memories"
]
},
{
"tid": "2435",
"name": "Bellini's",
"field_location_category": [
"Entertainment/Bars"
]
},
{
"tid": "2498",
"name": "Bullseye",
"field_location_category": [
"Pools, Sports & Spa"
]
}
当前 JSON:
{
"count": 70,
"language": "en",
"0": {
"id": "2420",
"title": "Medical Center",
"description": "The medical staff on-board are available for consultation; hours are posted in the Princess Patter. Please contact the Medical Center should you suffer from motion sickness and require a remedy. Professional services as well as medications are provided at reasonable costs. For medical emergencies, please dial 911. Your stateroom stateroom steward can provide you with the necessary safe waste receptacle if you have a medical condition that requires the use of sharps or needles.",
"time": "8:00am-10:00am & 4:30pm-6:30pm",
"manager": null,
"cover_charge": "",
},
"1": {
"id": "7840",
"title": "Conference Room - Deck 5 Portside",
"description": "Located on Deck 5 on both portside and starboard sides, the conference rooms onboard Regal Princess can be reserved for group meetings. Please enquire for details at the Passenger Services Desk.",
"time": null,
"manager": null,
"cover_charge": null,
},
"2": {
"id": "2426",
"title": "Conference Room - Deck 5 Starboard",
"description": "Located on Deck 5 on both portside and starboard sides, the conference rooms onboard Regal Princess can be reserved for group meetings. Please enquire for details at the Passenger Services Desk.",
"time": null,
"manager": null,
"cover_charge": "",
}
}
控制器是
var detailResult = $filter('filter')($scope.locationDetail, {id:path})[0];
这里 $scope.locationDetail 是我的 JSON 数据,path 是从 URL 获取的对应 ID。
我检查了$scope.locationDetail 和path,两者都正确。我认为问题出在最后一节{id:path})[0];。 id 引用不正确。
【问题讨论】: