我想在使用 get api 时使用数据库中的字段作为下拉列表
I want to use a field from database as a dropdown when I use get api
page.ts
getData() {
var link = 'http://servername/databasename/.php';
var data = JSON.stringify({});
this.http.post(link, data).subscribe(data => {
if (data == 0) {
this.data = false;
} else {
this.data = true;
this.result = data;
console.log(this.result);
this.result.leavetype;
console.log(this.result.leave_type);
}
});
}
page.html
<ion-item>
<ion-label color="medium">Leave</ion-label>
<ion-select [(ngModel)]="leavetype" name="leavetype">
<ion-select-option value="">{{leave_type}}</ion-select-option>
</ion-select>
</ion-item>
在此之后,我在这个数组中得到了数组形式的结果,我有一个名为 leavetype 的字段。我想要下拉列表中该字段的每个值。你能帮我看看我的代码吗?我希望你能理解我的问题谢谢你的帮助
在 ion-select-item
中使用“*ngFor”
<ion-item>
<ion-label color="medium">Leave</ion-label>
<ion-select [(ngModel)]="leavetype" name="leavetype">
<ion-select-option *ngFor="let val of result" value="">
{{val. leavetype}}
</ion-select-option>
</ion-select>
</ion-item>
page.ts
getData() {
var link = 'http://servername/databasename/.php';
var data = JSON.stringify({});
this.http.post(link, data).subscribe(data => {
if (data == 0) {
this.data = false;
} else {
this.data = true;
this.result = data;
console.log(this.result);
this.result.leavetype;
console.log(this.result.leave_type);
}
});
}
page.html
<ion-item>
<ion-label color="medium">Leave</ion-label>
<ion-select [(ngModel)]="leavetype" name="leavetype">
<ion-select-option value="">{{leave_type}}</ion-select-option>
</ion-select>
</ion-item>
在此之后,我在这个数组中得到了数组形式的结果,我有一个名为 leavetype 的字段。我想要下拉列表中该字段的每个值。你能帮我看看我的代码吗?我希望你能理解我的问题谢谢你的帮助
在 ion-select-item
中使用“*ngFor”<ion-item>
<ion-label color="medium">Leave</ion-label>
<ion-select [(ngModel)]="leavetype" name="leavetype">
<ion-select-option *ngFor="let val of result" value="">
{{val. leavetype}}
</ion-select-option>
</ion-select>
</ion-item>