[英]How to post multiple input fields to server as a JSON object in IONIC 3
I am relatively new to the IONIC app development. 我对IONIC应用程序开发比较陌生。 Now i am face a problem that,i need to send multiple input field which generate dynamically from the MySQL PHP. 现在我面临一个问题,我需要发送多个输入字段,这些输入字段是从MySQL PHP动态生成的。 ie, i have a input field which i can be updated and send to the server that is my requirement. 即,我有一个输入字段,可以更新该字段并将其发送到服务器,这是我的要求。
Now i am able to get data from my server and generate the input field.but iam unable to send the (updated if any) to the server back by clicking a button 现在我可以从服务器中获取数据并生成输入字段。但是我无法通过单击按钮将(更新后的)发送回服务器
<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>
here is the .ts file 这是.ts文件
loadStudents(division){
this.rest.loadStudents(division)
.subscribe(data=>{
this.students=data;
},error1 => {
console.log(error1);
});
}
You will get updated data in this.students
array itself : 您将在this.students
数组本身中获取更新的数据:
Just save the data on button click : 只需点击按钮保存数据:
HTML : HTML:
<button (click)="UpdateStudents()"> Save Updated Data </button>
TS : TS:
UpdateStudents(){
this.rest.UpdateStudents(this.students)
.subscribe(response=>{
console.log(response);
},error => {
console.log(error);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.