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}上面解构=路线
此答案无效