CrazyCodeBoy老湿,我昨天试了下SectionList,传了个datasouce进去,结果报'Cannot read property 'reduce' of undefined',我的rn版本是0.43,啥情况呢let food = [
{name: "Lettuce", category: "Vegetable"},
{name: "Apple", category: "Fruit"},
{name: "Orange", category: "Fruit"},
{name: "Potato", category: "Vegetable"}
];
export default class XYRecycle extends Component{
constructor(props){
super(props);
let ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2,
sectionHeaderHasChanged: (s1, s2) => s1 !== s2
});
this.state={
result:'',
dataSource:ds.cloneWithRowsAndSections(this.convertFoodArrayToMap()),
};
}
convertFoodArrayToMap(){
let foodCategoryMap = {}; // Create the blank map
food.forEach(function(foodItem) {
if (!foodCategoryMap[foodItem.category]) {
// Create an entry in the map for the category if it hasn't yet been created
foodCategoryMap[foodItem.category] = [];
}
foodCategoryMap[foodItem.category].push(foodItem);
});
return foodCategoryMap;
}
render(){
return(
contentContainerStyle={styles.listViewStyle}
renderItem={
({item}) => row
}
renderSectionHeader={
({section}) => section
}
dataSource={this.state.dataSource}
stickySectionHeadersEnabled={false}
/>
)
}
}
然后,
我打了断点也没发现sections属性

求大神指导
在使用React Native的SectionList组件时,遇到错误'Cannot read property 'reduce' of undefined'。问题出现在传入的dataSource上。代码中尝试将一个食品数组转换为键值对映射以便于SectionList处理,但在实际运行中未找到'sections'属性。已尝试在0.43版本的RN环境中复现问题,但未找到解决方案。
3793

被折叠的 条评论
为什么被折叠?



