私は、ドロップダウンメニューを持っている、と私は「すべて」オプションを選択すると、それは私のコンソール上でこのエラー与える:未定義のプロパティ '0'を読み取ることができません - javascriptエラー?
TypeError例外を:プロパティを読み取ることができません「0」未定義 のn個で$ scope.onSearchByChanged
$scope.loadEditorGroups = function() {
Reference.getEditorGroups($scope, function (response) {
$scope.filterScope.editorGroups = response.list;
if ($scope.filterScope.editorGroups.length > 0) {
$scope.filter.list.groupId = $scope.filterScope.editorGroups[0].id
}
});
};
:
ここ
$scope.onSearchByChanged = function() {
if ($scope.filter.list.searchBy == 'DEPARTMENT_CODE' && !$scope.filterScope.departments) {
$scope.loadDepartments();
} else if ($scope.filter.list.searchBy != 'DEPARTMENT_CODE') {
$scope.filter.list.departmentId = 0;
}
if ($scope.filter.list.searchBy == 'GROUP' && !$scope.filterScope.editorGroups) {
$scope.loadEditorGroups();
} else if ($scope.filter.list.searchBy != 'GROUP') {
$scope.filter.list.groupId = $scope.filterScope.editorGroups[0].id; //line 70
}
$scope.clearFilter('text');
};
if ($scope.filter.list.searchBy == 'GROUP' && !$scope.filterScope.editorGroups) {
$scope.loadEditorGroups();
}
if ($scope.filter.list.searchBy == 'DEPARTMENT_CODE' && !$scope.filterScope.departments) {
$scope.loadDepartments();
}
$scope.isStatusSelected = function (status) {
return _.indexOf($scope.filter.list.talentAssignmentStatuses, status) > -1;
};
$scope.selectTalentAssignmentStatus = function (status) {
$scope.clearFilter('text');
if ($scope.isStatusSelected(status)) {
_.remove($scope.filter.list.talentAssignmentStatuses, function (el) {
return status == el;
});
} else {
$scope.filter.list.talentAssignmentStatuses.push(status);
}
};
がloadEditorGroups機能である:(http://localhost:8080/js/jenkinsVersion/directives/assignment-filter.js:70:81)
だから、私は私のスクリプト、関数、行70、文字81に行ってきました
私はまだJSを学んでいます。このエラーはなぜ投げられるのですか?そのエディタグループリストから取得したいアイテムの値を変更すると、同じエラーが表示されますが、対応する番号が表示されます。あなたの助けに感謝します。私がさらなる情報を提供できるかどうか私に知らせてください。ありがとうございました!
おそらく '$ scope.filterScope.editorGroups'は空の配列なので、最初の配列項目を読み込もうとすると未定義です。 – Oriol
70:81は途中で行70、列81を意味します。 81行目は関係ありません。 – Jacob
'$ scope.filterScope.editorGroups'は' undefined'です。要素 '' 0 'にアクセスできません。 – ccjmne