我想在React Native滚动视图属性中添加一个条件。这是我的代码:
<ScrollView ref={(ref) => this._refScrollView = ref}
onContentSizeChange={this.scrollToEnd} refreshControl={
if(pullToRefresh == 'conversations'){
<RefreshControl
refreshing={this.state.refreshing}
onRefresh={this._onRefresh.bind(this)}
/>
}
}>
虽然是在给我一个错误,但我只想询问是否有任何可能的方法仅在RefreshControl
时才有PullToRefresh == 'conversations'
部分。
答案 0 :(得分:1)
您可以有条件地放置refreshControl
,尝试按照
<ScrollView
ref={(ref) => this._refScrollView = ref}
onContentSizeChange={this.scrollToEnd}
refreshControl={
(pullToRefresh == 'conversations') &&
<RefreshControl
refreshing={this.state.refreshing}
onRefresh={this._onRefresh.bind(this)}
/>
}
>
...
</ScrollView>
希望这会有所帮助!
答案 1 :(得分:1)
我不知道你得到了什么错误,但我认为这可能是语法错误。更改代码如下
<ScrollView
ref={(ref) => this._refScrollView = ref}
onContentSizeChange={this.scrollToEnd}
refreshControl={
(pullToRefresh == 'conversations') && {
<RefreshControl
refreshing={this.state.refreshing}
onRefresh={this._onRefresh.bind(this)}
/>
}
}
>