2013-10-12 55 views
0

我有一个对象数组“休假”angularjs + jquery:如何在Foreach循环中访问数组中的数组元素?

$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; 

但这不起作用

可以做些什么?

回答

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

相关问题