【问题标题】:FlatList not RenderingFlatList 未呈现
【发布时间】:2018-01-15 20:21:56
【问题描述】:

我正在尝试使用 FlatList,但 FlatList 无法正常工作。 -安卓

这个作品

<FlatList
  data={[{key: 'a'}, {key: 'b'}]}
  renderItem={({item}) => <Text>{item.key}</Text>}
/>

这不行

 <FlatList       
     data={this.state.dataSource}
     keyExtractor={this._keyExtractor}   
     renderItem={({ item}) =>{console.log(item);}}
    >

【问题讨论】:

  • 你的意思是它不工作?就像您的调试器中没有日志语句一样?
  • 我的调试器没有写任何东西。
  • 你能在这里复制粘贴this.state.dataSourcethis._keyExtractor吗?我做了同样的事情,但我的记录项目没有问题,所以我想这是因为这两个有问题
  • 我用ListView没有问题,但是我用的是FlatList,它不写数据。
  • 如果您不在这里复制粘贴代码,我无法回答您的问题,我正在做同样的事情,但我的调试器显示了我正在完美记录的对象,有很多原因会发生这种情况,没有您的代码,几乎不可能识别出任何类型的问题。据我所知,this.state.dataSource 可能是一个空数组

标签: reactjs react-native react-native-flatlist


【解决方案1】:

好的,我找到了问题,就在你的componentWillMount

componentWillMount() {
    return fetch('...')
        .then((response) => {
            return response.json();
        })
        .then((responseJson) => {
            let ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });
            this.setState({
                isLoading: false,
                dataSource: ***ds.cloneWithRows(responseJson).rowIdentities***
            });
        });
}

我像你最初所做的那样做了console.log(ds.cloneWithRows(responseJson)),但得到了这样的东西:

我们关心的数据在rowIdentities

【讨论】:

  • rowIdentities 不是用于 ListView 吗?它与 Flatlist 有什么关系?
猜你喜欢
  • 2019-03-17
  • 2021-12-15
  • 1970-01-01
  • 2021-03-25
  • 2020-03-10
  • 1970-01-01
  • 2020-06-20
  • 2019-05-22
  • 1970-01-01
相关资源
最近更新 更多