如何从Angular JS的其余调用响应中获取键的数组值? [英] How to get array value of key from rest call response in angular js?

查看:135
本文介绍了如何从Angular JS的其余调用响应中获取键的数组值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Angular JS进行一次休息电话.我可以从响应中获取简单的键值.但是当键的值采用数组形式时,我就无法在angular js控制器中获取值.

I am making a rest call in angular js. I am able to get simple key value from response. But when key's value in array form then I am not able to get value in angular js controller.

我正在共享我的相关代码(不相同).

I am sharing my related code(Not Same).

Rc.all('demo/example/db/').get('quues/').then(function(res)
  {
   $scope.demo={}
   $scope.demo.details={         
     value1 : res.Ksus.Type.Master.Origin.ID,        
       }

 $scope.array={}
   $scope.array.arrValue={         
     arrVal : res.Asus[0].AsuID,        
       }
   }

JSON:

{
  _id:123
  Ksus: {
       Type: {
       Master: {
         Origin: {
                  ID: "Demo"
                }
              }
            }
       },
 Asus: [{
     AsuID: "f4",
     Type: "SU",     
     }]
}

我想获取控制器中的 AsuID 值.我可以在没有数组的控制器中获得简单的键值,如 ID:"Demo" .但是我想获得数组值.当我尝试 arrVal:res.Asus [0] 时,会在控制台中给 0 未定义的值.请提前对此表示感谢.

I want to get AsuID value in controller. I am able to get simple key value without array in controller like ID: "Demo". But I want to get array value. When I tried arrVal : res.Asus[0], Then It is give 0 undefined value in console. Please give some idea for this thanks in advance.

推荐答案

这是因为您在get方法之外引用了res. 下面的代码将为您提供所需的数据.

This is because you are referencing res outside the get method. Below code will give you the required data.

 Rc.all('demo/example/db/').get('quues/').then(function(res)
  {
   $scope.demo={}
       $scope.demo.details={         
          value1 : res.Ksus.Type.Master.Origin.ID,        
       }
       $scope.array={}
       $scope.array.arrValue={         
          arrVal : res.Asus[0].AsuID,        
       }
    }

这篇关于如何从Angular JS的其余调用响应中获取键的数组值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆