如何破坏 .map 函数?下面附上代码示例。一旦索引达到 5,我想打破外观,因为我只想将 5 Avatar 渲染到屏幕上。
<View style={{ flexDirection: 'row', marginTop: 20, marginLeft: 30 }}>
{
peopleGroup.map((people, i) => {
if(i<5) {
return (
<Avatar
key={people.id}
width={30}
position='absolute'
containerStyle={{ transform: [{translate: [-28 + (28 * i), 0, 1 - (i * 0.1)]}] }}
small
rounded
source={{uri: people.image}}
activeOpacity={0.7}
/>
)
}else if(i===5) {
return (
<View key={i} style={{ transform: [{translate: [(25 * i), 9, 0]}] }}>
<Text>{peopleGroup.length}</Text>
</View>
)
}
}
)
}
</View>