简体   繁体   English

React Native 渲染函数抛出错误

[英]React Native render function throws error

Here is my render function of react native.这是我的反应原生渲染功能。 if i put listview it works.如果我把列表视图它的工作原理。 if i put touchablehighlight it works.如果我把 touchablehighlight 它工作。 but, if it put both it doesn't work.但是,如果两者都放它就行不通了。 need help.需要帮忙。

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>
    );
},

what is wrong here?这里有什么问题? need both components to work.需要两个组件才能工作。

You can't have 2 tags that you can return.您不能有 2 个可以返回的标签。 You should wrap it inside a <View> </View> tag.您应该将其包装在<View> </View>标签中。 This way you can abstract multiple components that you need in the page.通过这种方式,您可以抽象页面中需要的多个组件。

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>
    );
},

Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM