代码之家  ›  专栏  ›  技术社区  ›  Ali Zia

我可以在SurrVIEW属性中添加自定义条件吗?

  •  0
  • Ali Zia  · 技术社区  · 7 年前

    我想在react native scroll view属性中添加一个条件。这是我的代码:

    <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' .

    2 回复  |  直到 7 年前
        1
  •  1
  •   Prasun    7 年前

    你可以有条件地放 refreshControl ,请尝试以下操作

    <ScrollView 
        ref={(ref) => this._refScrollView = ref}
        onContentSizeChange={this.scrollToEnd}
        refreshControl={
            (pullToRefresh == 'conversations') &&
            <RefreshControl
                refreshing={this.state.refreshing}
                onRefresh={this._onRefresh.bind(this)}
            />
        }
    >
    ...
    </ScrollView>
    

    希望这会有帮助!

        2
  •  1
  •   Hariharan L    7 年前

    我不知道你会得到什么错误,但我想可能是语法错误。更改代码如下

    <ScrollView 
      ref={(ref) => this._refScrollView = ref}
      onContentSizeChange={this.scrollToEnd} 
      refreshControl={
        (pullToRefresh == 'conversations') && {
          <RefreshControl
            refreshing={this.state.refreshing}
            onRefresh={this._onRefresh.bind(this)}
          />
        }
      }
    >
    
    推荐文章