【问题标题】:React Native render function throws errorReact Native 渲染函数抛出错误
【发布时间】:2016-03-29 18:49:50
【问题描述】:

这是我的 react native 的渲染函数。如果我把 listview 它工作。如果我把touchablehighlight它工作。但是,如果它把两者都放了它就行不通了。需要帮助。

render: function() {
    return (
      /* ListView wraps ScrollView and so takes on its properties.
       With that in mind you can use the ScrollView's contentContainerStyle prop to style the items.*/
        <ListView
          contentContainerStyle={styles.list}
          dataSource={this.state.dataSource}
          renderRow={this._renderRow}/>
        <TouchableHighlight onPress={() => this._pressRow(rowID)} underlayColor="transparent">
        </TouchableHighlight>
    );
},

这里有什么问题?需要这两个组件才能工作。

【问题讨论】:

    标签: javascript android react-native


    【解决方案1】:

    您不能有 2 个可以返回的标签。您应该将其包装在 &lt;View&gt; &lt;/View&gt; 标记中。这样您就可以抽象出页面中需要的多个组件。

    render: function() {
        return (
          /* ListView wraps ScrollView and so takes on its properties.
           With that in mind you can use the ScrollView's contentContainerStyle prop to style the items.*/
          <View>  
            <ListView
              contentContainerStyle={styles.list}
              dataSource={this.state.dataSource}
              renderRow={this._renderRow}/>
            <TouchableHighlight onPress={() => this._pressRow(rowID)} underlayColor="transparent">
            </TouchableHighlight>
          </View>
        );
    },
    

    希望对你有帮助。

    【讨论】:

    • 如果我必须传递道具,我也可以使用视图吗?
    • 是的,视图是一个组件。你可以用你的 ListView 做任何事情。我的意思是,所有 react-native 组件中的共同点也可以在 上使用。
    猜你喜欢
    • 1970-01-01
    • 2019-11-15
    • 1970-01-01
    • 1970-01-01
    • 2019-03-21
    • 2023-01-04
    • 1970-01-01
    • 2020-06-07
    • 1970-01-01
    相关资源
    最近更新 更多