Java connot reduce_Cannot read property 'reduce' of undefined

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

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属性

c7444e4dbf2d09264629cebc58206316.png

求大神指导

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值