简体   繁体   English

如果 with 或语句不起作用 - javascript

[英]If with or statement does not work - javascript

In my app this validation check works for one condition and not working if I want to check it for 2 conditions:在我的应用程序中,此验证检查适用于一种情况,如果我想检查两种情况则不起作用:

if (!admin.isMemberOf('group2')) {...} //works

if (!admin.isMemberOf('group1') || !admin.isMemberOf('group2')) {...} // not working

In order to do check for any of these I can simply use ||为了检查其中任何一个,我可以简单地使用|| but It returns false for both groups.但它对两个组都返回 false。 How to use it right in this case?在这种情况下如何正确使用它? Thank you.谢谢你。

edit: full condition编辑:完整状态

   if (!req.user.roles.admin.isMemberOf('root2') || !req.user.roles.admin.isMemberOf('admins2')) {
     workflow.outcome.errors.push('You may not create account groups.');
     return workflow.emit('response');
   }

edit2 I know the question sounded silly but I was trying to do it straightforward as according to what i needed - prevent some action, if the member is member of all groups, except the pointed one (or several) groups. edit2我知道这个问题听起来很傻,但我试图根据我的需要直接做 - 如果成员是所有组的成员,除了指出的一个(或多个)组,请防止某些操作。 of course it can be replaced with "not this and other group"当然也可以换成“not this and other group”

您需要一个逻辑 AND && ,因为 OR 的条件始终为true

if (!admin.isMemberOf('group1') && !admin.isMemberOf('group2')) {...} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM