React Native:SectionList 从 renderItem 获取 header
React Native: SectionList get header from renderItem
我正在尝试从 renderItem 获取 header 名称,但它给了我未定义的名称。我需要清单的名称,所以我试图将其传递给 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>
);
};
我正在尝试从 renderItem 获取 header 名称,但它给了我未定义的名称。我需要清单的名称,所以我试图将其传递给 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>
);
};