0

我有一个对象数组“假期”

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

但这不起作用

可以做什么?

4

1 回答 1

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

于 2013-10-12T15:19:12.993 回答