我正试图从renderItem中获取标头名称,但它给了我未定义的名称。我需要一个清单的名称,所以这就是我试图将其传递给renderItem的原因。
这是我的密码,有人能帮我吗?
const List = (props) => {
const list = [
{
"id": "G1600789684218",
"data": [
{
"id": "G1600789684218",
"value": "Going Skating",
},
],
"name": "Jack Ross",
}
]
const renderList = ({ item }, name) => {
console.log("item name is", name);
return (
<View>
<ListItem title={item.value} />
</View>
);
};
return (
<SectionList
sections={list}
keyExtractor={(item, index) => index}
renderSectionHeader={({ section: { name, data } }) =>
<Text style={styles.heading}>{name}</Text>
}
renderItem={renderList}
/>
);
};
export default List;
我认为,你的renderList应该是这样的,
// section has entire data passed for section
const renderList = ({ item, section }) => {
console.log("item name is", section.name);
return (
<View>
<ListItem title={item.value} />
</View>
);
};