react-native - 在反应原生的渲染中做一个循环
问题描述
我正在尝试在我的渲染中做一个循环。我用push(在循环中)放入了一个变量很多'uri'
test.push(data.link)
现在,有了流行音乐,我想画出所有的照片。现在我正在像那样手动执行此操作
return (
<View style={styles.container}>
<Image style={ { width: 400, height: 400 } } source={ { uri: test.pop() } } />
<Image style={ { width: 400, height: 400 } } source={ { uri: test.pop() } } />
<Image style={ { width: 400, height: 400 } } source={ { uri: test.pop() } } />
<Image style={ { width: 400, height: 400 } } source={ { uri: test.pop() } } />
<Image style={ { width: 400, height: 400 } } source={ { uri: test.pop() } } />
<Image style={ { width: 400, height: 400 } } source={ { uri: test.pop() } } />
</View>
)
但我无法绘制所有图片,因为我需要为每张图片都这样做。有人知道我可以如何显示所有照片或特定数量,而不必像上面那样为每个 pone 做一张
解决方案
你不应该pop()
你的阵列。相反,您可以使用map
, 它将增加数组的每个条目并对其进行处理。例如:
return (
<View style={styles.container}>
{test.map(link => (
<Image style={ { width: 400, height: 400 } } source={ { uri: link } } />
))}
</View>
)
推荐阅读
- json - 由 protojson 库生成的 JSON 中未显示 Protobuf 自定义选项
- amazon-web-services - 错误代码:AccessDeniedException。用户:arn:aws:iam::xxx:user/xxx 无权执行:lambda:CreateEventSourceMapping on resource:*
- laravel - 方法 Illuminate\Database\Eloquent\Collection::attach 在 laravel 8 中不存在错误
- python - 如何识别 Python 打开的 MySQL 中打开的连接
- sql - 如何在 .NET Core 的实体框架中的原始 SQL 中添加 CAST
- javascript - 在material-ui中为DatePicker添加自定义按钮
- opencv - 如何在 CUDA 内核中正确操作 CV_16SC3 Mat
- python - 根据当前时间和上次更新时间之间的小时计算时差
- powerapps - Powerapps - 无法从 Flow 获得响应
- ubuntu - 将 postinst 添加到 debian 版本