Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native react native中的多个if-else条件_React Native - Fatal编程技术网

React native react native中的多个if-else条件

React native react native中的多个if-else条件,react-native,React Native,我必须根据条件显示不同的图标 Icon name={route.routeName=='Profile'?“home”:“calendar”} 我在route.routeName中有四个项目。如果route.routeName中只有2个项目,则可以正常工作。有人能帮我弄清楚如何在这样的场景中设置多个if-else条件吗?可以这样做: { (route.routeName=='Profile') && <Icon name='Profile/> } { (rout

我必须根据条件显示不同的图标

Icon name={route.routeName=='Profile'?“home”:“calendar”}


我在route.routeName中有四个项目。如果route.routeName中只有2个项目,则可以正常工作。有人能帮我弄清楚如何在这样的场景中设置多个if-else条件吗?

可以这样做:

{
 (route.routeName=='Profile') &&
 <Icon name='Profile/>
}
{
 (route.routeName=='home') &&
 <Icon name='Home'/>
}
{
 (route.routeName=='calendar') &&
 <Icon name='calendar'/>
}
{
(route.routeName=='Profile')&&

也许您的代码{(route.routeName==='Profile'&&使用单个
&
的更紧凑版本看起来已经很干净了。我通常不使用
|
,因为它会在同一行中考虑,不适合多种情况,也许可以尝试在
const{routeName}上面解构=路线
此答案无效