【问题标题】:How to post multiple input fields to server as a JSON object in IONIC 3如何在 IONIC 3 中将多个输入字段作为 JSON 对象发布到服务器
【发布时间】:2018-12-08 06:54:09
【问题描述】:

我对 IONIC 应用程序开发比较陌生。 现在我面临一个问题,我需要发送从 MySQL PHP 动态生成的多个输入字段。 即,我有一个输入字段,我可以对其进行更新并发送到我要求的服务器。

现在我可以从我的服务器获取数据并生成输入字段。但是我无法通过单击按钮将(如果有的话更新)发送回服务器

   <ion-list>
  <ion-item no-margin="">
  <ion-grid>
    <strong><ion-row>
      <ion-col>Student code</ion-col>
      <ion-col>name</ion-col>
      <ion-col>phone</ion-col>
    </ion-row>
    </strong>
  </ion-grid>
  </ion-item>
  <ion-grid>
    <ion-row *ngFor="let student of students">
      <ion-col >{{student.student_code}}</ion-col>
      <ion-col>{{student.full_name}}</ion-col>
      <ion-col ion-item=""><ion-input  maxlength="10" required [(ngModel)]="student.phone"></ion-input></ion-col>
    </ion-row>
  </ion-grid>
</ion-list>

这是 .ts 文件

    loadStudents(division){
this.rest.loadStudents(division)
.subscribe(data=>{
this.students=data;

  },error1 => {
    console.log(error1);
  });

}

【问题讨论】:

    标签: javascript php angular ionic-framework


    【解决方案1】:

    您将在this.students 数组本身中获得更新的数据:

    只需在点击按钮时保存数据:

    HTML:

    <button (click)="UpdateStudents()"> Save Updated Data </button>
    

    TS:

    UpdateStudents(){
      this.rest.UpdateStudents(this.students)
      .subscribe(response=>{
           console.log(response);
      },error => {
           console.log(error);
     });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多