我对 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);
});
}
最佳答案
您将在 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/