Javascript 从response.data.js获取特定值
我想从响应中获得特定值,这是我的jsJavascript 从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
$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
;