0

我有简单的 footerTab,如果有通知,我想在其中显示徽章。

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

使用此代码,我得到“未定义徽章”

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

4

1 回答 1

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>
于 2017-03-31T17:33:36.453 回答