【问题标题】:angularjs + jquery : How to access array element within array in Foreach Loop?angularjs + jquery:如何在 Foreach 循环中访问数组中的数组元素?
【发布时间】:2013-10-12 15:18:14
【问题描述】:

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

$scope.Vacations = [{Id:'1' ,VacationType = {TypeId='1' ,TypeName = 'test'}}];

它包含其他对象数组“假期类型”,只有一组

我要提取TypeId

我做了这样的事情:

$scope.selectedVacationType = [];
$scope.TypeTd;

$scope.selectedVacationType=Vacations.VacationType;
$scope.TypeTd;= $scope.selectedVacationType[0].Id;

但这不起作用

可以做什么?

【问题讨论】:

    标签: jquery arrays angularjs


    【解决方案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

    【讨论】:

      猜你喜欢
      • 2012-07-09
      • 2010-12-29
      • 2012-02-15
      • 2017-08-20
      • 2012-01-20
      • 1970-01-01
      • 2018-06-13
      • 2015-08-23
      相关资源
      最近更新 更多