我刚开始接触本机,我想知道如何在返回值内处理map函数。
根据此处给出的答案Using react props in .map function,我将代码修改如下:
render()
{
const { active } = this.state
const drawerContent = Object.keys(drawerItems).map(section => {
return <DrawerComponent.Section key={section.toLowerCase()} title={section} style={styles.section}>
{drawerItems[section].map(item =>
<DrawerComponent.Item
key={item.id}
label={item.label}
icon={item.icon}
style={styles.item}
active={active === item.id}
onPress={() => nav.push(item.screen + 'Screen', item.props || {})}
/>
)}
</DrawerComponent.Section>
})
return(<View style={styles.container}>{drawerContent}</View>)
}
这是最好的方法还是任何更好的优化方法?
答案 0 :(得分:0)
对我来说看起来不错。不过,我会考虑使用How to numerically integrate vector data in Matlab?而不是Object.keys
。