简体   繁体   English

react native 为什么我的条件不起作用?

[英]react native why is my condition not working?

I want to show components when one of the three product categorys are selected.我想在选择三个产品类别之一时显示组件。

Its not working.它不工作。

 { step === 2 && (product.category.category_name === 'clothing') || (product.category.category_name === 'accessoires') || (product.category.category_name === 'shoes') && return (<View><Text>Hello</Text></View> ) }

If clothing or accessoires or shoes exists then I want to show a component.如果存在服装、配饰或鞋子,那么我想展示一个组件。 Its not working why ?它不工作为什么? If I remove all except clothing then it works.如果我去除除衣服以外的所有东西,那么它就起作用了。

I think you should chain better your conditionals && and ||我认为你应该更好地链接你的条件&&|| . .

Try this code:试试这个代码:

if (step === 2) 
{ 
 if (product.category.category_name === 'clothing' ||
     product.category.category_name === 'accessoires' ||
     product.category.category_name === 'shoes' )
   { 
     return (<View><Text>Hello</Text></View> )
   }
 }

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

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