[英]React-Native Flat List RenderList Issue
I have a react-native project, using a FlatList that takes data from a node backend. 我有一个本机项目,使用从节点后端获取数据的FlatList。
The data is retrieved from the backend, stored in the redux store and is mapped as this.props.entries which I don't have any issue accessing the data normally by mapping over it. 从后端检索数据,将其存储在redux存储中,并映射为this.props.entries,通过映射它来正常访问数据没有问题。
The issue I'm having is that I can't access the data inside RenderItem. 我遇到的问题是我无法访问RenderItem中的数据。
Here is the data coming from the node backend. 这是来自节点后端的数据。
{ startingBalance: 1000,
entries:
[ TextRow {
owner_id: 56,
id: 1324,
date: 2019-01-22T00:00:00.000Z,
name: 'Groceries ',
amount: '58.00',
type: 'debit',
rec: null,
balance: '942.00' },
TextRow {
owner_id: 56,
id: 1457,
date: 2019-06-04T00:00:00.000Z,
name: 'zxc',
amount: '233.00',
type: 'credit',
rec: null,
balance: '1175.00' },
TextRow {
owner_id: 56,
id: 1459,
date: 2021-06-30T00:00:00.000Z,
name: 'Test',
amount: '100.00',
type: 'credit',
rec: 'Tes_shtkalrk',
balance: '1275.00' },
TextRow {
owner_id: 56,
id: 1460,
date: 2021-06-30T00:00:00.000Z,
name: 'Test',
amount: '100.00',
type: 'credit',
rec: 'Tes_shtkalrk',
balance: '1375.00' } ],
transactions: [] }
I then have the following code for my FlatList 然后,我的FlatList有以下代码
render() {
if (this.props.entries) {
const data = Object.values(this.props.entries);
return (
<View>
<Text>Data</Text>
<FlatList
data={data}
renderItem={entry => <Text>Name: {entry.name}</Text>}
/>
</View>
);
} else {
return (
<View>
<Text>No DATA</Text>
</View>
);
}
}
The FlatList is obviously getting my data as I have 4 items in this.props.entries and the result of running the code produces 4 outputs like below: FlatList很明显是在获取我的数据,因为我在this.props.entries中有4个项目,运行代码的结果将产生4个输出,如下所示:
Data
Name:
Name:
Name:
Name:
But for whatever reason "entry.name" isn't returning anything. 但是无论出于何种原因,“ entry.name”都不会返回任何内容。
You need to destructure the input to renderItem
with the right property name, item
. 您需要使用正确的属性名称
item
将输入renderItem
为renderItem
。
For example, each element in your list is passed as the property item
on an object, so you should have 例如,列表中的每个元素都作为对象的属性
item
传递,因此您应该
<FlatList
data={data}
renderItem={({ item }) => <Text>Name: {item.name}</Text>}
/>
https://facebook.github.io/react-native/docs/flatlist#renderitem https://facebook.github.io/react-native/docs/flatlist#renderitem
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.