【问题标题】:FlatList doesn't show anything when retrieving data with redux使用 redux 检索数据时,FlatList 不显示任何内容
【发布时间】:2019-11-29 08:29:12
【问题描述】:

我正在尝试使用 FlatList,但即使提供给列表的数据是正确的,它也没有显示任何内容(我在控制台将其记录在 render() 上方,它显示的数组很好)

我尝试映射库,然后将其传递给组件,但这只会使数组在屏幕上重复 9 次(这是数组长度)

` 

renderItem(Library){
        return <ListItem myLibrary={Library} />
    }

    render(){
        return(
            <FlatList 
            data={this.props.Libraries}
            renderItem={this.renderItem}
            keyExtractor={Library => Library.title}
            />
        );
    }
}

const mapStateToProps = (state) => {
    return {Libraries: state.Libraries}
}
`

导出默认连接(mapStateToProps)(RenderLibraries); `

在另一个组件中:

         `  <Text>
                {this.props.myLibrary.title}
            </Text> `

【问题讨论】:

  • 试试这个 this.props.myLibrary.item.title
  • @CuongTranDuc 成功了,比你好多了!

标签: react-native redux react-redux react-native-flatlist


【解决方案1】:

传递给 renderItem 的每个数据项都将包装在 item 对象中。检查docs

renderItem({ item }){
    return <ListItem myLibrary={item} />
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-10
    相关资源
    最近更新 更多