【问题标题】:Passing return values from php api array to another page将返回值从 php api 数组传递到另一个页面
【发布时间】:2019-01-19 03:36:35
【问题描述】:

在我的 ionic 应用程序中,我尝试将从 php api 返回的数组传递到另一个页面,但它没有传递任何值

在 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>

userHome.ts

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); 
  }

在同一页面上,这是我尝试传递值的推送导航

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

  }

在 post.ts 中,我将它添加到了构造函数中

this.navParams.get(this.postList);

然后在我的 post.html

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

请问,如何将 api 的返回值传递到另一个页面?

谢谢。

【问题讨论】:

    标签: php arrays api ionic-framework ionic2


    【解决方案1】:

    因此,如果您查看 ionic doc example,您会发现您需要使用 json 对象传递数据并使用其键来检索数据,请尝试以下方法:

    在您的第一个组件中:

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

    在接收组件构造函数中;

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

    如果仍然困难,请分享完整的代码,但这应该很容易解决;)

    【讨论】:

      【解决方案2】:

      你可以这样做

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

      在post.ts中,你可以通过

      this.navParams.get('postList');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-12-19
        • 1970-01-01
        • 2017-01-25
        • 1970-01-01
        • 1970-01-01
        • 2012-11-07
        • 2012-04-27
        相关资源
        最近更新 更多