React Native渲染函数抛出错误

时间:2015-12-23 10:47:08

标签: javascript android 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>
    );
},

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

1 个答案:

答案 0 :(得分:1)

您无法返回2个标签。您应该将其包装在<View> </View>标记内。这样,您就可以在页面中抽象出所需的多个组件。

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

希望它有所帮助。

相关问题