>有谁知道这是我的代码的错误还是问题?
目前,我正在尝试使用带有http get的每个来检索rss提要,它只显示来自一个rss提要的数据,这种情况不应该如此。但是,在控制台日志中,它模拟正确的行为。
请帮忙,我几天来一直在尝试解决。
我的网页代码
<div *ngFor="let category of favouritecategories | async"><h3 class="header" [id]="category.name">{{category.name}}</h3>
<ion-item-sliding *ngFor="let item of xmlItemsApac; let i=index" #slidingItem>
<ion-item *ngIf="i<articlecount" text-wrap>
<div class (click)="openbrowser(item.link)"><h2>{{item.title}}</h2>
<p class="block-with-text"> {{item.description}}</p></div>
</ion-item>
<ion-item-options side="right">
<button ion-button color="custom" (click)="bookmark(item.title,item.description,item.link,slidingItem)"><ion-icon name="bookmark"></ion-icon>Bookmark</button>
</ion-item-options>
<ion-item *ngIf="i>articlecount" [hidden]="!showMoreAmericas" text-wrap>
<div class (click)="openbrowser(item.link)"><h2>{{item.title}}</h2>
<p class="block-with-text"> {{item.description}}</p></div>
</ion-item>
<ion-item-options side="right">
<button ion-button color="custom" (click)="bookmark(item.title,item.description,item.link,slidingItem)"><ion-icon name="bookmark"></ion-icon>Bookmark</button>
</ion-item-options>
</ion-item-sliding>
<button ion-item (click)="toggleMoreArticle()" text-center detail-none large>
<h4 class="showMoreText"><ion-icon name="arrow-down" *ngIf="!arrows"></ion-icon>
<ion-icon name="arrow-up" *ngIf="arrow"></ion-icon> {{buttonText}}</h4>
</button><br/>
</div>
我的打字稿
this.af.database.list(`/users/${userid}/favourites`)
.subscribe(snapshots => {
snapshots.forEach(snapshot => {
this.Apac = this.http.get( snapshot.regions[0].rss)
this.Apac.map(res => res.text())
.subscribe((data) => {
this.parseXML(data)
.then((data) => {
this.xmlItemsApac = data;
console.log(this.xmlItemsApac)
});
});
});
});
您正在替换 this.xmlItemsApac
中的 rss 条目。您需要将其初始化为空数组。 this.xmlItemsApac=[]
并推动价值观
this.af.database.list(`/users/${userid}/favourites`)
.subscribe(snapshots => {
snapshots.forEach(snapshot => {
this.Apac = this.http.get( snapshot.regions[0].rss)
this.Apac.map(res => res.text())
.subscribe((data) => {
this.parseXML(data)
.then((data) => {
this.xmlItemsApac.push(data);
console.log(this.xmlItemsApac)
});
});
});
});