Listview没有显示在react-native中

时间:2017-03-13 06:09:50

标签: react-native

我使用react native listview编写了一些代码。它正确呈现,根本没有任何错误;但是,列表视图根本没有显示。有人可以建议吗?下面是我的代码。非常感谢你

import React, { Component } from 'react';
import { Stylesheet, View, ListView, Text } from 'react-native';
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 != r2});

class Listvieweg extends Component {
  constructor() {
    super()

    this.state = {
      dataSource: ds.cloneWithRows([{
        title: 'Why is the sky blue?',
        author: 'George'
      }])
    }
  }

  renderRow(rowData) {
    return (
    <View>
      <Text>
        {rowData.title}
      </Text>
      <Text>
        {rowData.author}
      </Text>
    </View>
    )
  }

  render() {
    return (
      <View>
        <ListView
          style={styles.list}
          enableEmptySections={true}
          dataSource={this.state.dataSource}
          renderRow={(rowData) => this.renderRow(rowData)}
        />
      </View>
    )
  }
}

const styles = {
  list: {
    flex: 1
  }
}

export default Listvieweg;

1 个答案:

答案 0 :(得分:4)

  <View style={{flex:1}}>
    <ListView
      ....
    />
  </View>