有谁知道这是我的代码的错误还是问题?
目前我正在尝试使用带有http get的forEach来检索rss feed,它只显示来自一个rss feed的数据,但不应该是这种情况。但是,在控制台日志中,它正在模拟正确的行为。
请帮助,我一直试图解决几天。
我的Html代码
<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)
});
});
});
});
答案 0 :(得分:0)
您正在替换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)
});
});
});
});