我正在將 Ionic 和 Firestore 用于我的網路應用程式。在一個組件中,我顯示了來自 firestore 資料庫的專案串列,在 url tabs/items/list-detail/和其他按鈕修改影像中的專案的詳細資訊,然后有一個按鈕回傳 url tabs/items/。之后,如果我回傳到選項卡/專案/串列詳細資訊頁面,我希望使用修改后的專案重新加載串列,但頁面保持不變。我曾嘗試使用 ViewWillEnter 但不起作用。
在專案的 html 頁面中,有一個按鈕可以導航到詳細資訊頁面:
<ion-button id="detail" *ngIf="registeredAndUpl?.registered!=true" [routerLink]="['/tabs/items/list-detail',id]">View</ion-button>
這是組件串列-詳細資訊頁面:
export class DetailPage implements OnInit, ViewWillEnter {
items: any
userId: any
item0: any
item1: any
constructor(private route: ActivatedRoute, private router: Router,
public authService: AuthenticationService,
) {}
ngOnInit() {
}
ionViewWillEnter() {
this.myDefaultMethodToFetchData();
}
myDefaultMethodToFetchData() {
console.log("IN")
this.getItems().then((data) => {
console.log("IN2222")
this.items = data
this.item0 = this.items[0];
this.item1 = this.items[1];
})
this.userId = this.authService.userData.uid;
}
returnItems(){
this.router.navigate(['/tabs/items/']);
}
getItems() {
const itemsRef = firebase.firestore().collection("user_orders/" this.userId "/reservations")
.where("ordini", "<", 10).limit(5);
return itemsRef.get()
.then((querySnapshot) => {
return querySnapshot.docs.map(doc => doc.data());
})
.catch((error) => {
console.log("Error getting documents: ", error);
});
}
然后,在 html 頁面中,我有一個按鈕來回傳專案:
<ion-content>
<div style="display:flex;">
<div *ngIf="item0" style="flex:1;">
<video id="video1" height="320" width="240" controls>
<source src="{{item0?.downloadURL}}" type="video/mp4">
<source src="{{item0?.downloadURL}}" type="video/ogg">
</video>
</div>
<div *ngIf="item1" style="flex:1;">
<video id="video2" height="320" width="240" controls>
<source src="{{item1?.downloadURL}}" type="video/mp4">
<source src="{{item1?.downloadURL}}" type="video/ogg">
</video>
</div>
</div>
</ion-content>
<ion-button id="button1" (click)="returnItems()">Return</ion-button>
what am i doing wrong? I've noticed that every time I switch from items to list detail page, using the ionViewWillEnter() method, and try to print something in console, the print is recalculated but the data remain the same, so the problem I think is in html page:

uj5u.com熱心網友回復:
ionViewWillEnter 應該可以作業。嘗試 ionViewDidEnter。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/358045.html
標籤:ionic-framework google-cloud-firestore
上一篇:離子無限滾動新推送的影像不加載
