function ($scope, $stateParams, $http, WineService, $rootScope) {
var wineList = [];
getAllWineIDsOfEvent();
setAttributesOfWine();
function getAllWineIDsOfEvent() {
var wineIDofEvent = $($scope.tableEntries_AT_Event_Wine).filter(function (i, n) { return n.Event_ID === $scope.actEvent; });
wineList = [];
for (var i = 0; i < wineIDofEvent.length; i++) {
var Wine = { id: wineIDofEvent[i].Wine_ID };
wineList.push(Wine);
}
}
//set missing Attributes of Wine
function setAttributesOfWine() {
for (var i = 0; i < $scope.tableEntries_wine.length; i++) {
var wineofEvent = $($scope.tableEntries_wine).filter(function (i, n) { return n.id === wineList[i].id; });
}
$rootScope.WineOfEvent = wineList;
}}])
我每次要过滤$scope.tableEntries_wine
时都会收到Cannot read property 'id' of undefined
错误。
我认为这与我的$scope.tableEntries_wine
有关。
这是它的样子:
[{
"id": "a66f426e-8466-42b6-bda5-86e39bb3b708",
"createdAt": "2017-02-02T23:05:02.927Z",
"updatedAt": "2017-02-02T23:06:01.763Z",
"version": "AAAAAAAAHoU=",
"deleted": false,
"Name": null,
"Wineyear": 1998,
"Region_Description": "",
"Qualitylevel": "",
"Winetype_ID": "cb897aee-b32a-4802-894f-2936e9018ff5",
"Winzer_ID": "65a71e4c-a761-42c7-9291-541e55e3784a"
},
{
"id": "daf4557e-b6a0-4506-af25-c6b4e49c3790",
"createdAt": "2017-02-02T23:06:59.630Z",
"updatedAt": "2017-02-02T23:20:53.079Z",
"version": "AAAAAAAAHpw=",
"deleted": false,
"Name": null,
"Wineyear": 2012,
"Region_Description": "",
"Qualitylevel": "",
"Winetype_ID": "cb897aee-b32a-4802-894f-2936e9018ff5",
"Winzer_ID": "65a71e4c-a761-42c7-9291-541e55e3784a"
},
{
"id": "9ab3d9c4-f2ff-4547-8a4b-883fd78a3842",
"createdAt": "2017-02-02T23:41:08.108Z",
"updatedAt": "2017-02-16T07:15:08.723Z",
"version": "AAAAAAAAH1Q=",
"deleted": false,
"Name": null,
"Wineyear": 1998,
"Region_Description": "Süddings",
"Qualitylevel": "Qualitylevel 1",
"Winetype_ID": "cb897aee-b32a-4802-894f-2936e9018ff5",
"Winzer_ID": "eb3c0ce8-a8d0-47dc-9a49-2261dd0513f7"
},
{
"id": "3b920bfa-f549-474c-beca-1384503af421",
"createdAt": "2017-02-16T07:15:12.582Z",
"updatedAt": "2017-02-16T07:15:15.253Z",
"version": "AAAAAAAAH1w=",
"deleted": false,
"Name": null,
"Wineyear": 2001,
"Region_Description": "",
"Qualitylevel": "",
"Winetype_ID": "cb897aee-b32a-4802-894f-2936e9018ff5",
"Winzer_ID": "eb3c0ce8-a8d0-47dc-9a49-2261dd0513f7"
}]
当我将$scope.tableEntries_wine
替换为具有属性ID的另一个表时,我不会收到错误。
wineList
看起来像这样:
[{
"id": "a66f426e-8466-42b6-bda5-86e39bb3b708"
},
{
"id": "9ab3d9c4-f2ff-4547-8a4b-883fd78a3842"
},
{
"id": "3b920bfa-f549-474c-beca-1384503af421"
}]
有人有想法吗?