我有这个功能:
$scope.doPaste = function(destination) {
if ($scope.selectCopy.ids != []) {
console.log("will copy");
$scope.CopyFiles(destination);
}
if ($scope.selectMove.ids != []) {
console.log("will move");
$scope.MoveFiles(destination);
}
};
在我的应用中,$scope.selectMove.ids
和 $scope.selectCopy.ids
不能都是非空的。我的意思是,例如当 $scope.selectMove.ids
为非空时 $scope.selectCopy.ids
为空。
我的问题是,在控制台中,我总是看到 will copy 和 will move。
最佳答案
注意 [] != []
返回 true
(因为它们是不同的对象)。
您应该使用length
来检查数组是否为空。
if($scope.selectCopy.ids.length > 0){
console.log("will copy");
$scope.CopyFiles(destination);
}
关于javascript - 使用angular JS检查数组是否为空的条件语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29828578/