将属性传递给组件

时间:2017-03-31 12:58:55

标签: javascript react-native native-base

我有简单的footerTab,如果有通知,我想展示徽章。

server-main.js

使用此代码我得到'徽章未定义'

如何为Button传递该徽章属性?

1 个答案:

答案 0 :(得分:0)

过了一会儿,我意识到属性徽章是布尔值,默认为true。所以工作版就是这样。

    <Button active={ this.props.ui.selectedTab === 'notifications' ? true : false } 
        onPress={ () => this.selectedTab('notifications') }
        badge={ this.props.ui.notifications ? true : false }    
    >
        { this.props.ui.notifications ? 
          <Badge><Text style={{ color:'white' }}>
       {this.props.ui.notifications}</Text></Badge> : null
        }
        <Icon name='md-notifications' />
    </Button>
相关问题