Javascript 跳过对象';循环中的属性
我有一个这样的物体:Javascript 跳过对象';循环中的属性,javascript,angularjs,Javascript,Angularjs,我有一个这样的物体: $scope.someFilter = {}; 在后面的代码中,我用属性填充它(例如): 等等。我需要的是在“if语句”中检查这些属性是否为空,即没有值,但以这样的方式 $scope.someFilter.Id 及 不应该被检查,因为它们是强制性的,所以它们总是有一些值。除了这两个属性之外,所有其他属性都应该检查是否有值 我试过了 if(Object.keys($scope.somefilter).length == 0) 但它不起作用,因为它得到了这两个属性的值 如
$scope.someFilter = {};
在后面的代码中,我用属性填充它(例如):
等等。我需要的是在“if语句”中检查这些属性是否为空,即没有值,但以这样的方式
$scope.someFilter.Id
及
不应该被检查,因为它们是强制性的,所以它们总是有一些值。除了这两个属性之外,所有其他属性都应该检查是否有值
我试过了
if(Object.keys($scope.somefilter).length == 0)
但它不起作用,因为它得到了这两个属性的值
如果这个问题很愚蠢,我很抱歉,我对angularjs和一般编程都是新手。我已经尝试过该代码,但是
areEmptyProps
即使在我发送$scope.someFilter.Number时返回true,例如值为5。我也尝试了tempScope[prop].length==0,但再次变为真。更正的解决方案,立即尝试我不确定为什么会投反对票,但我现在尝试并成功了。非常感谢。
let tempScope = Object.assign({}, $scope.someFilter);
delete tempScope.Name;
delete tempScope.Id;
let areEmptyProps = Object.keys(tempScope).every((prop) => (tempScope[prop] === undefined || tempScope[prop].toString().length === 0))
if (areEmptyProps) {}
if(Object.keys($scope.somefilter).length == 0)
let tempScope = Object.assign({}, $scope.someFilter);
delete tempScope.Name;
delete tempScope.Id;
let areEmptyProps = Object.keys(tempScope).every((prop) => (tempScope[prop] === undefined || tempScope[prop].toString().length === 0))
if (areEmptyProps) {}