HE *_*hao 8 reactjs react-native
如何打破.map功能?代码示例如下.我希望在索引达到5时打破外观,因为我只想将5个头像渲染到屏幕上.
<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>
Run Code Online (Sandbox Code Playgroud)
Tom*_*Tom 15
Array.slice在映射之前使用.
peopleGroup
.slice(0, 5) // creates a copy of original, 5 items long
.map(...) // subsequent operations work on the copy
Run Code Online (Sandbox Code Playgroud)
田田!
| 归档时间: |
|
| 查看次数: |
6896 次 |
| 最近记录: |