react native根据判断数据源是否为空不同显示问题?

render() {

...
    {
        dataSource != null : (
                    <ListView />
           ) : (
                    <Components2 />
        )

    }

...


}

希望是dataSource为空时显示<Components2 />组件,目前是dataSource不为空确实显示<ListView />数据,dataSource为空也不显示<Components2 />,请大家指教

阅读 9.6k
1 个回答

所以问题是如何写对三目运算符的语法?

答案是:

dataSource ? (
                    <ListView />
           ) : (
                    <Components2 />
        )
推荐问题