0

我的目標是將數據傳遞到同一頁面。我無法理解這個概念。我還是新來的離子btw。我的request.html代碼檢索請求Firebase控制檯的所有請求。如何將數據傳遞迴同一頁面

<ion-header> 
    <ion-navbar color="primary"> 
    <ion-title name="title">Job Requests</ion-title> 
    </ion-navbar> 
</ion-header> 

<ion-content padding> 
    <div class="filter"> 
<button class="islandwide" ion-button large>Islandwide</button> 
<button class="nearby" ion-button large (click)="openMapPage()">Nearby</button> 
</div> 

<ion-list> 
    <ion-card *ngFor="let user of request | async" class="job"> 
    <button ion-item (click)="goToJobDetails(user.$key)" class="info"> 
    <ion-avatar class="avatar" item-start> 
     <img src="../assets/icon/user_male-512.png"> 
    </ion-avatar> 
    <h2 class="name">{{user.regdetails.username}}</h2> 
    <p text-wrap class="address"><ion-icon name="compass"> 
     </ion-icon> {{user.regdetails.address}}</p> 
    <p id="key">{{user.$key}}</p> 
    </button> 
    </ion-card> 
</ion-list> 

</ion-content> 

我的構造函數:

constructor(public navCtrl: NavController, public navParams: NavParams, 
      angFire: AngularFireDatabase) { 

    this.request = angFire.list('/request'); 
    this.userreq = angFire.list(`${this.userkey}`); 
    this.reqdetails = angFire.list('reqdetails'); 

    } 

openMapPage()方法

基本上這個方法返回所有誰只有reqdetails用戶,並將數據傳回request.html頁面

openMapPage() 
    { 

    var ref = firebase.database().ref("request"); 
    ref.once("value").then((snapshot) => { // <------ Here! 
     var a = snapshot.exists(); // true 
     var c = snapshot.hasChild("reqdetails"); // true 
     var d = snapshot.child('reqdetails').exists(); 
     var requestsKey = snapshot.key; 
     var requestsValue = snapshot.val(); 

     snapshot.forEach((childSnapshot) => { // <------ And here! 
      var requestKey = childSnapshot.key; 
      var requestValue = childSnapshot.val(); 

      var reqdetails = requestValue.reqdetails; 
      if (reqdetails) { 

       this.data = requestKey; 
       console.log(this.data); 
       //this.arr.push(requestKey); 
       //console.log(this.arr); 
      } 

     }); 
     this.navCtrl.push(RequestsPage, { 'param1': this.data }); 
    }); 


} 

這就是從請求表中獲取所有數據後,將看起來像。這是默認視圖,意味着它從firebase獲取所有請求記錄。

enter image description here

,現在我面臨這個問題。當用戶點擊並觸發request.html中的我的openMapPage()方法時,它將重定向到openMapPage。如何重定向誰只有reqdetails用戶的數據,以相同的HTML頁面request.html

我已經試過這到目前爲止

this.navCtrl.push(RequestsPage, { 'param1': this.data }); 

但它仍然呈現的整體要求,這意味着它具有不已被過濾。

+0

什麼是您的console.log(this.data);'打印 –

+0

它打印出只有reqdetails的所有用戶密鑰。 – Suresh

+0

如何返回到request.html頁面? – Suresh

回答

0

好吧,它解決了。

openMapPage() 
    { 


    var ref = firebase.database().ref("request"); 
    ref.once("value").then((snapshot) => { // <------ Here! 
     var a = snapshot.exists(); // true 
     var c = snapshot.hasChild("reqdetails"); // true 
     var d = snapshot.child('reqdetails').exists(); 
     var requestsKey = snapshot.key; 
     var requestsValue = snapshot.val(); 

     snapshot.forEach((childSnapshot) => { // <------ And here! 
      var requestKey = childSnapshot.key; 
      var requestValue = childSnapshot.val(); 

      var reqdetails = requestValue.reqdetails; 
      if (reqdetails) { 
       this.data = requestKey; 
       console.log(this.data); 
       //this.arr.push(requestKey); 
       //console.log(this.arr); 
       this.getRequest = this.angFire.list('request', { 
        query: { 
        orderByChild: 'reqdetails', 
        startAt: 'reqdetails' 
      } 
     }) 

      } 
     }); 
/*  this.navCtrl.push(RequestsPage, { 
      thing1: this.data 
     });*/ 

     //this.navCtrl.push(RequestsPage, { 'param1': this.data }); 
    });  
    } 
相關問題