繁体   English   中英

如何在IONIC 3中将多个输入字段作为JSON对象发布到服务器

[英]How to post multiple input fields to server as a JSON object in IONIC 3

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

}

这是动态加载的html模板

您将在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);
 });
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM