Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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
获取数据json对象的特定属性_Json_Angularjs - Fatal编程技术网

获取数据json对象的特定属性

获取数据json对象的特定属性,json,angularjs,Json,Angularjs,我希望访问我从服务返回的数据的特定属性 因此,基本上我希望能够以某种方式达到$scope.users.name,我知道用户是数组中的对象,但是我可以以任何方式达到该特定属性吗?希望这个问题足够清楚 $scope.users = []; UserService.getAll().then( function (data) { $scope.users = data; }, function (err) { c

我希望访问我从服务返回的数据的特定属性

因此,基本上我希望能够以某种方式达到$scope.users.name,我知道用户是数组中的对象,但是我可以以任何方式达到该特定属性吗?希望这个问题足够清楚

$scope.users = [];

    UserService.getAll().then(
        function (data) {
            $scope.users = data;
        }, function (err) {
            console.log(err);
        }
    );

我假设您收到的数据是数组形式的。如果你知道索引,那么你可以这样做

$scope.users[2].name
其中2是要知道其name属性的对象的索引

或者您可以尝试使用js函数forEach

$scope.users.forEach(function (user) {
  console.log(user.name);
});
该函数将迭代所有对象,您可以在传入的回调中访问它们的属性


希望这就是你要找的。

这就是你要找的吗?