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

标签 javascript php angular ionic-framework

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

}

here is the html template which dynamically loaded

最佳答案

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

关于javascript - 如何在 IONIC 3 中将多个输入字段作为 JSON 对象发布到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51095616/

相关文章:

php - Magento - 从数据库手动将订单从 1.4 迁移到 1.7

css - 我如何在 angular-cli 中使用 bootstrap mixins

angular - 如何在不触发表单更改事件的情况下将 FormGroup 添加到 FormArray

javascript - 如何将函数传递到自己的 react 上下文提供程序中以允许您编辑状态?

javascript (reactJS) 访问子数组中的值的最佳方法

php - 使用 PHP 备份数据库

php - PHP 开放标签 “<?=” 和 “<?php”/“<?” 之间有什么区别?

angular - 如果 ng-content 有内容或为空 Angular2

javascript - 构建计算器时遇到困难

javascript - 在 HTML map 的特定位置添加叠加层