reactjs - React Native 通过 API 调用访问图像
问题描述
如何从我的反应本机应用程序访问当前 json 结构中的图像-
[
{
"id": "1",
"height": "160",
"student": {
"name": "John",
"studentImages": [
{
"thumbnail": true,
"path": "https://..."
},
{
"thumbnail": false,
"path": "https://..."
}
]
}
}
]
我目前拥有的是-
return this.state.studentDataList.map((studentData) => {
return (
<View>
<Card image={require('img')}>
<Text>{studentData.student.name}</Text>
</Card>
</View>
)
})
对于卡片图像,我需要访问student.studentImages.path
并获取具有缩略图的图像为真。我如何访问它?
解决方案
您需要从缩略图图像数组中过滤掉,才能为您提供第一个正确的缩略图。
return this.state.studentDataList.map((studentData) => {
let thumbnailData = studentData.student.studentImages;
let image = thumbnailData.find((img) => img.thumbnail);
let imageSrc = image.path || '';
return (
<View>
<Card image={imageSrc}>
<Text>{studentData.student.name}</Text>
</Card>
</View>
)
})
推荐阅读
- json - Spring Boot中的CSV到JSON,具有多种类型的记录
- python - 是否有任何可用于 AD 组策略操作的 python 库?
- react-native - 将 React Native 功能组件转换为类组件
- javascript - 登录后如何使用 URL 中的名称将用户呈现到主页?
- c# - 如何在c#中将带有Byte的字符串转换为字节数组
- javascript - 如何以编程方式设置 -webkit-print-color-adjust:与 Javascript 完全一致?
- azure-data-factory-2 - 有没有办法在多个映射数据流中重用单个正在运行的 databricks 集群
- c# - 如何更改自定义字段的值(\Areas\Identity\Pages\Account\Manage\Index.cshtml.c)?
- javascript - 如何制作问卷调查机器人?
- keras - 如何一一提供数据以使用 tensorflow 2.0 版本进行训练