2013-10-12 54 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

相關問題