angularjs+;jquery:如何在Foreach循环中访问数组中的数组元素?
我有一个对象数组“休假”angularjs+;jquery:如何在Foreach循环中访问数组中的数组元素?,jquery,arrays,angularjs,Jquery,Arrays,Angularjs,我有一个对象数组“休假” $scope.Vacations = [{Id:'1' ,VacationType = {TypeId='1' ,TypeName = 'test'}}]; 它只包含一个集合的其他对象数组“VacationType” 我想提取TypeId 我做过这样的事: $scope.selectedVacationType = []; $scope.TypeTd; $scope.selectedVacationType=Vacations.VacationType; $scop
$scope.Vacations = [{Id:'1' ,VacationType = {TypeId='1' ,TypeName = 'test'}}];
它只包含一个集合的其他对象数组“VacationType”
我想提取TypeId
我做过这样的事:
$scope.selectedVacationType = [];
$scope.TypeTd;
$scope.selectedVacationType=Vacations.VacationType;
$scope.TypeTd;= $scope.selectedVacationType[0].Id;
但这是行不通的
可以做什么?使用
$scope.selectedVacationType=Vacations[0]。VacationType代码>
Vacations
表示项目列表[…]
顺便说一句,您的型号错误,请删除=
并替换为:
$scope.Vacations = [{
Id: '1',
VacationType : {
TypeId : '1',
TypeName : 'test'
}
}];
HTML
selectedVacationType: <pre>{{selectedVacationType|json}}</pre>
TypeTd: <pre>{{TypeTd|json}}</pre>
TypeName: <pre>{{TypeName|json}}</pre>
演示
$scope.Vacations = [{
Id: '1',
VacationType : {
TypeId : '1',
TypeName : 'test'
}
}];
$scope.selectedVacationType = $scope.Vacations[0].VacationType;
$scope.TypeTd = $scope.selectedVacationType.TypeId;
$scope.TypeName = $scope.selectedVacationType.TypeName;