Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.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对象属性_Javascript_Angularjs_Object_Angularjs Scope - Fatal编程技术网

如何获取javascript对象属性

如何获取javascript对象属性,javascript,angularjs,object,angularjs-scope,Javascript,Angularjs,Object,Angularjs Scope,我正在尝试获取对象属性,它也是一个对象 $scope.posts = Post.find(); console.log($scope.posts); 在控制台中,这将返回我: [$promise: Promise, $resolved: false] >0: Resource //this is an object that I need >1: Resource >2: Resource >$promise: Promise

我正在尝试获取对象属性,它也是一个对象

$scope.posts = Post.find();
console.log($scope.posts);
在控制台中,这将返回我:

[$promise: Promise, $resolved: false]
    >0: Resource   //this is an object that I need
    >1: Resource
    >2: Resource
    >$promise: Promise
    $resolved: false
    >__proto__: Array[0]
如何获取资源0、1和2?

因为
Post.find()
正在返回承诺,您应该在
then()的解析回调中使用assign返回的数据

它将返回一个数组,可以使用索引访问该数组的元素

Post.find().then(function(data){
    $scope.posts = data;
    console.log($scope.posts[0]); //Access the first element of array
})

$scope.posts[0]??我想你可以做更多的研究,这是bacis的问题,我相信你可以自己找到解决方案……为同样的问题创建JSFIDLE/jsbin。我做了研究。我试图通过继承人的钥匙得到这件物品。它只返回$promise和$resolved。不是资源。$scope.posts不是数组。它是一个对象,不工作$scope.posts[0]未定义。我想先这么做。@neeev:注意这个答案中
然后
的用法。这是非常重要的。然后是不工作,但我知道如何获得回调函数。数据给了我正确的答案。谢谢