我有一个对象阵列'假期'
$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;
但这不起作用
可以做些什么?
答案 0 :(得分:1)
使用$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;
演示 Fiddle