【发布时间】:2019-06-18 16:28:15
【问题描述】:
我正在尝试在离子卡上显示来自 json 的图像。我在控制台日志中收到 JSON 响应,但无法显示图像。所以我最终有一张空白卡。我显然在 html 中搞砸了一些东西。任何帮助都会非常感谢您!下面是一张空卡的截图。
主页.Html
<ion-card>
<ion-card-content>
<ion-item *ngFor="let attribute of attributes">
<img data-src='{{attribute.pic_url}}' />
<ion-card-title>
{{attributes.description}}
</ion-card-title>
</ion-item>
</ion-card-content>
</ion-card>
home.ts
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
private storymap : FormGroup;
private title: string;
private author: string;
private link: string;
private inputName='';
private result: any;
private data: Observable<any>;
private appid = this.inputName.substring(this.inputName.indexOf("appid=")+6,this.inputName.length);
private subtitle: string;
private attributes: string[];
private geometry: any[] = [];
private photo: string[];
constructor(public navCtrl: NavController, public http:HttpClient, private formBuilder: FormBuilder) {
this.storymap = this.formBuilder.group({
storymapurl: [''],
title: ['', Validators.required],
author: [''],
description: [''],
});
}
logForm(){
if ( this.inputName.length > 3 ) {
this.appid = this.inputName.substring(this.inputName.indexOf("appid=")+6,this.inputName.length);
console.log(this.appid);
fetch(`https://www.arcgis.com/sharing/rest/content/items/${this.appid}/data?f=json`)
.then(response => response.json())
.then(metadata => {
this.title = metadata["values"]["title"]
//console.log(this.title)
this.subtitle = metadata["values"]["subtitle"]
this.author = metadata["values"]["author"]
//console.log(this.subtitle)
return fetch(`https://www.arcgis.com/sharing/rest/content/items/${metadata["values"]["webmap"]}/data?f=json`)
})
.then(response => response.json())
.then(data => {
let data_res = Array.of(data);
this.attributes = Object.keys(data_res["operationalLayers"]["0"]["featureCollection"]["layers"]["0"]["featureSet"]["features"]["0"]["attributes"]);
console.log(this.attributes.pic_url);
this.geometry = Object.keys(data["operationalLayers"]["0"]["featureCollection"]["layers"]["0"]["featureSet"]["features"]["0"]["geometry"])
//this.photo = Object.keys(data["operationalLayers"]["0"]["featureCollection"]["layers"]["0"]["featureSet"]["features"]["0"]["attributes"]["pic_url"])
//console.log(this.photo)
console.log(data)
return this.attributes
});
}
console.log(this.storymap.value)
} }
【问题讨论】:
-
什么 console.log(attribute.pic_url);说?很可能是空的。
-
正确的@Whatatimetobealive
-
我需要帮助获取 url 链接
-
console.log(this.attributes)的结果是什么?如果你在这里发布数组会更好,而不是屏幕截图。 -
' (7) ["name", "description", "icon_color", "pic_url", "thumb_url", "is_video", "OBJECTID"] 0: "name" 1 : "description" 2: "icon_color" 3: "pic_url" 4: "thumb_url" 5: "is_video" 6: "__OBJECTID" 长度: 7 __proto: Array(0)'
标签: html json image typescript ionic-framework