[英]How to access array of objects inside $scope
I am trying to access an array of objects within $scope. 我试图访问$ scope中的对象数组。
If I console.log($scope) (see image below) it displays the pedigree object that I would like to access. 如果我console.log($ scope)(请参见下图),它将显示我想访问的谱系对象。 However, if I console.log($scope.pedigree) I get undefined.
但是,如果我使用console.log($ scope.pedigree),则无法定义。 If I console.log(typeof $scope.pedigree) I get object.
如果我console.log(typeof $ scope.pedigree)我得到对象。
Can someone help me access pedigree? 有人可以帮助我获得血统书吗?
Pedigree is an array of objects, not a single object. 谱系是对象的数组,而不是单个对象。 As a result, you need to access the appropriate instance by index to get your object.
因此,您需要按索引访问适当的实例以获取对象。
var pedigree = $scope.pedigree[0];
There is no "array" type in Javascript. Javascript中没有“数组”类型。 As a result, when you use
typeof
on your $scope.pedigree
property, it will tell you it is of type object, even though happens to be an array of objects. 结果,当您在
$scope.pedigree
属性上使用typeof
时,即使碰巧是一个对象数组,它也会告诉您它是object类型的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.