Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从response.data.js获取特定值_Javascript_Angularjs - Fatal编程技术网

Javascript 从response.data.js获取特定值

Javascript 从response.data.js获取特定值,javascript,angularjs,Javascript,Angularjs,我想从响应中获得特定值,这是我的js $scope.cari = function () { $http.get('http://localhost:8089/MonitoringAPI/webresources/login?a='+$scope.userid+'&d='+$scope.password).then(function(response){ $scope.reslogin = response.data; $scope.res

我想从响应中获得特定值,这是我的js

$scope.cari = function () {
        $http.get('http://localhost:8089/MonitoringAPI/webresources/login?a='+$scope.userid+'&d='+$scope.password).then(function(response){
        $scope.reslogin = response.data;
        $scope.reslogin2 = response.data.lsmenu.idmenu;
        console.log($scope.reslogin);
        console.log($scope.reslogin2);


  });
      };
但是当我输入console.log时,
$scope.reslogin2
会给我未定义的值。这是我的回答

[{“userid”:“1234”,
“用户名”:“里斯坦”,
“posisi”:“ITSupport”,

“lsmenu”:[{“idmenu”:“1”,“parentidmenu”:“11”,“parentnamemmenu”:“监控”,“urlmmenu”:“lalalala.html”}]}]

应该是,response.data是一个数组,lsmenu也是一个数组

$scope.reslogin2 = response.data[0].lsmenu[0].idmenu;

根据您发布的内容,您的响应是一个数组(lsmenu也是如此)。因此,您应该从lsmenu中获取数组的第一个元素和第一个元素

$scope.cari = function () {
    $http.get('http://localhost:8089/MonitoringAPI/webresources/login?a='+$scope.userid+'&d='+$scope.password).then(function(response){
    $scope.reslogin = response.data;
    $scope.reslogin2 = response.data[0].lsmenu[0].idmenu;
    console.log($scope.reslogin);
    console.log($scope.reslogin2);


    });
  };

尝试响应[0]。lsmenu[0][“idmenu”]或
响应[0]。lsmenu[0]。idmenu