arrays - 在一个 .Json 对象中添加两个图像
问题描述
我正在使用 Ionic 3 构建一个移动应用程序,并且我正在尝试使用数组在一个离子卡中显示一些图像。
HTML:
<ion-card>
<img [src]="productDetails.images"/>
<ion-card-header>
Description
</ion-card-header>
<ion-card-content>
{{productDetails.description}}
</ion-card-content>
</ion-card>
JSON文件:
[
{
"id": "1",
"name": "Oreo",
"description": "Our pre-shrunk organic cotton t-shirt, with its slightly fitted waist and elegant V-neck is designed to flatter. Youll want one in every color!",
"price": "520.00",
"image": "https://podcollective.com/wp-content/uploads/2016/07/Love-is-a-Cosmic-Force-Alex-Grey.jpg",
"images": [
"https://podcollective.com/wp-content/uploads/2016/07/Love-is-a-Cosmic-Force-Alex-Grey.jpg",
"https://podcollective.com/wp-content/uploads/2016/07/Love-is-a-Cosmic-Force-Alex-Grey.jpg"
],
"bestSeller": true,
}
]
使用“productDetails.image”时,我只能成功显示一张图像,但尝试使用“productDetails.images”时却不能。
我明白了:
我的问题是,是否可以显示两个图像?或者唯一的选择是创建更多对象值并手动显示它们?
解决方案
好吧,因为 productDetails.images 是一个数组,因此当您使用它时,您不会返回到图像的链接,而是链接数组本身,所以如果您使用 productDetails.images[0] 那么您将拥有第一个图像等
推荐阅读
- python-3.x - 有什么作用!在 Python 中是什么意思?
- python - 如何使用 TD Ameritrade api 使用 python 创建监视列表?
- python - gpflow 示例中的 2D 实现和获取 MAE、RMSE 错误
- c++ - 如果我们为 const integer 分配这样的值可以吗?
- python-3.x - 为什么我的 Pygame 窗口背景无法加载?
- python - 一种保护数据库中密码的简单方法
- android-studio - 在android studio中构建失败,没有任何错误
- java - 解决转帐逻辑
- python - 通过遵循 Python 中值的特定路径替换嵌套字典中的值
- javascript - 在滚动时调整大小的矩形过渡被切断