0
我正在構建一個離子3應用程序,我面臨一個奇怪的問題。 我最近加入這個模塊來我的應用程序,以使數據緩存: https://www.npmjs.com/package/ionic-cachengFor不刷新數據
它工作得很好,在我的應用程序的所有頁面,除了從以下之一:
<ion-header>
<ion-navbar>
<ion-title>{{navParams.get('name')}}</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-segment [(ngModel)]="view">
<ion-segment-button value="info">
Info
</ion-segment-button>
<ion-segment-button value="recensioni">
Recensioni
</ion-segment-button>
</ion-segment>
<div [ngSwitch]="view">
<div id="info">
<div *ngSwitchCase="'info'">
<div class="flexBox">
<div *ngIf="details != undefined" [style.background]="(details.open_now) ? 'green' : 'red'"></div>
<span *ngIf="details != undefined && details.open_now">Aperto</span>
<span *ngIf="details != undefined && !details.open_now">Chiuso</span>
<ion-icon name="call" (click)="call()"></ion-icon>
<ion-icon name="navigate" (click)="navigateTo()"></ion-icon>
</div>
</div>
<div #map2 [style.height]="(view == 'info') ? '35vh' : '0px'"></div>
<div *ngSwitchCase="'info'" id="slides">
<ion-slides *ngIf="details != undefined">
<ion-slide *ngFor="let img of details.photos" (click)="openImg($event)">
<img [src]="'https://maps.googleapis.com/maps/api/place/photo?key=AIzaSyD_9bj_Ao6nklX7PWrM_1E-iDH4EPVWV6A&maxwidth=1600&photoreference=' + img.photo_reference" />
</ion-slide>
</ion-slides>
</div>
</div>
<div id="rec">
<div *ngSwitchCase="'recensioni'">
<ion-list-header>
<div id="avg">
<div>
<span item-start text-wrap>Voto Google: </span>
<span item-end text-wrap class="end" *ngIf="navParams.get('rating') != undefined">{{navParams.get('rating')}}/5</span>
<span item-end text-wrap class="end" *ngIf="navParams.get('rating') == undefined">Nessuna valutazione!</span>
</div>
<div>
<span item-start text-wrap class="start">Voto Tripadvisor: </span>
<ion-spinner item-end text-wrap class="end" *ngIf="!loaded" name="dots"></ion-spinner>
<span item-end text-wrap class="end" *ngIf="loaded && rating != undefined">{{rating}}/5</span>
<span item-end text-wrap class="end" *ngIf="loaded && rating == undefined">Nessuna valutazione!</span>
</div>
</div>
</ion-list-header>
<ion-list>
<ion-item *ngFor="let recensione of reviews">
<div class="center">
<ion-avatar>
<img [src]="recensione.profile_photo_url">
</ion-avatar>
</div>
<p class="name">{{recensione.author_name}}</p>
<div class="rating">
<div class="star-ratings-sprite">
<span [style.width]="(100*recensione.rating/5) + '%'" class="star-ratings-sprite-rating"></span>
</div>
</div>
<div *ngIf="recensione.title != undefined" class="title">
<span text-wrap>{{recensione.title}}</span>
</div>
<span class="review" text-wrap>{{recensione.text}}</span>
<div class="date">
<p>{{recensione.relative_time_description}}</p>
</div>
</ion-item>
</ion-list>
<ion-spinner *ngIf="!loaded"></ion-spinner>
<ion-infinite-scroll (ionInfinite)="scrapeNext($event)" threshold="1000px">
<ion-infinite-scroll-content></ion-infinite-scroll-content>
</ion-infinite-scroll>
</div>
</div>
</div>
</ion-content>
在這個頁面我秀有關特定餐廳的信息和評論(評論顯示在離子列表中)。 要檢索的評論我用下面的代碼中的.ts文件:
this.scraper.getTaReviews(this.navParams.get('name'))
.subscribe(data => {
console.log(data)
if (data != "no data") {
this.placeId = data.placeId;
this.risId = data.risId;
this.hasNext = data.hasNext;
this.rating = data.avgRating;
this.reviews = this.reviews.concat(data.reviews);
console.log(this.reviews);
}
this.loaded = true;
})
很顯然,我發起了審查變量是在構造一個空數組。
這是被稱爲使HTTP調用該函數:
getTaReviews(ris: string) {
let request = this.http.get(this.hostname + ':8090/tarev?ris=' + ris + '&citta=' + this.share.getProvincia()).map(res => res.json()).retry();
return this.cache.loadFromObservable(ris + "-" + this.share.getProvincia(), request);
// return this.http.get(this.hostname + ':8090/tarev?ris=' + ris + '&citta=' + this.share.getProvincia()).map(res => res.json()).retry();
}
未註釋的部分是新的,而且評論部分是舊的工作之一。 我的問題是,我第一次打開頁面並獲取數據,一切正常,離子列表中的評論顯示正確。但是,當我使用緩存數據時,即使評論數組包含正確的數據(我在控制檯日誌中檢查過它),列表中的離子項目也未填充。正如我之前所說的,如果我不使用ionic-cache,它就可以工作,但我無法真正解釋爲什麼此行爲僅影響此頁面。此外,所有其他緩存的數據(除了評論)都可以正確顯示,看起來這只是ngFor語句的問題。