代码之家  ›  专栏  ›  技术社区  ›  Tonye Boro

将返回值从php api数组传递到另一页

  •  0
  • Tonye Boro  · 技术社区  · 6 年前

    在user.html页面中,我有一个按钮,当单击该按钮时,将值传递到下一页

    <button ion-button icon-only (click)="goToResult()">
        <ion-icon ios="ios-log-out" md="md-log-out" class="user"></ion-icon> Next
    </button>
    

    ngOnInit(){
    
    this.phone = this.navParams.get('phone');
    
    
    var headers = new Headers();
    
    headers.append("Accept", 'application/json');
    
    headers.append('Content-Type', 'application/json' );
    
    let options = new RequestOptions({ headers: headers });
    
    let data = {
    
        phone: this.phone
    
         };
    
    let loader = this.loading.create({
    
    content: 'Loading Page Contents',
    
    });
    
    loader.present().then(() => {
    
    this.http.post('http://mypro.com/eApi/retrieve.php',data, options)
    
    .map(res => res.json())
    
        .subscribe(res => {
    
         loader.dismiss()
    
        this.items=res.server_response;
    
        console.log(this.items);
    
        });
    
        });
        //this.navCtrl.push(PostPage, data); 
      }
    

    在同一页上,这是我试图传递值的push nav

    goToResult(){
        console.log(this.items);
          this.navCtrl.push(PostPage,
            this.postList = this.items
          )
    
      }
    

    this.navParams.get(this.postList);
    

    然后在我的 post.html网站

    <ion-title *ngFor="let post of postList">{{post.Name}}
            </ion-title>
    

    请告诉我,如何将返回值从api传递到另一个页面?

    2 回复  |  直到 6 年前
        1
  •  1
  •   Sergey Rudenko    6 年前

    因此,如果您检查离子文档示例,您将看到需要使用json对象传递数据并使用其键检索数据,请尝试以下方法:

       this.navCtrl.push(PostPage,
            { postList: this.items } 
       )
    

    在接收组件构造器时;

    this.postList = this.navParams.get(“postList”);
    

    如果仍然挣扎,请共享完整的代码,但这应该很容易解决;)

        2
  •  0
  •   Anandh Sp    6 年前

    你可以这样做

    goToResult(){
        console.log(this.items);
          this.navCtrl.push(PostPage, {postList = this.items})
    }
    

    在post.ts中,您可以通过

    this.navParams.get('postList');