[英]How do I use the includes method in lodash to check if an object is in the collection?
[英]How do I use lodash to check every item in a collection except those that dont meet my condition?
let allChecked = _.every(this.collection, this.checked);
我有这个现有的代码,如果集合中的每个项目对于checked
的属性都为 true,则返回 true。 我想修改它,而不是迭代集合中的每个项目,只迭代另一个属性上没有 true 的项目。 即,对于集合中的项目,还有另一个名为disabled
的属性。 如果此属性设置为 true,我想从_.every()
检查中完全忽略这些项目。
您可以在_.reject
this.collection
删除集合中指定属性为 true 的任何项目。
一个例子就像_.every(_.reject(this.collection, 'disabled'), this.checked)
只需在短路检查中添加disabled
即可。 如果disabled
为true
,您可以跳过检查:
let allChecked = _.every(this.collection, obj => obj.disabled || this.checked(obj));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.