我正在使用 Angular,我正在尝试访问数组内的一些内容。
在此行上,您将看到 console.log(JSON.stringify($scope.lineItems))
,它在浏览器控制台上返回 [[]]
。如果我在同一行检查/设置断点,这就是我所拥有的信息:
> 0: Array[0]
length: 1
> __proto__: Array[0]
如果您单击> 0: Array[0]
,则另一部分将打开显示此内容
> 0: Array[0]
length: 0
__proto__: Array[0]
> length: 1
__proto__: Array[0]
现在,我需要做的是,当 0: Array[0]
显示一个警报时,noLinesAlert.show()
这是我的代码,实际上不起作用,因为我很困惑,我不知道如何访问我需要的信息:
$scope.lineItems = lines;
console.log(lines);
console.log(JSON.stringify($scope.lineItems));
if ($scope.lineItems.length === 0) {
noLinesAlert.show();
}else {
noLinesAlert.hide();
}
}
最佳答案
根据您的描述,您需要这个:
if ($scope.lineItems[0].length === 0) {
noLinesAlert.show();
} else {
noLinesAlert.hide();
}
关于javascript - AngularJS - 尝试访问数组以返回警报时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27786764/