【问题标题】:I want to use a field from database as a dropdown when I use get api当我使用 get api 时,我想使用数据库中的字段作为下拉列表
【发布时间】:2019-12-26 15:19:43
【问题描述】:

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 的字段。我想要下拉列表中该字段的每个值。请你帮我看看我的代码。我希望你能理解我的问题谢谢你的帮助

【问题讨论】:

    标签: php html css ionic4 angular8


    【解决方案1】:

    在离子选择项中使用“*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> 

    【讨论】:

      猜你喜欢
      • 2019-01-04
      • 2023-02-06
      • 2013-10-25
      • 1970-01-01
      • 2021-02-08
      • 2019-09-24
      • 2020-02-12
      • 1970-01-01
      • 2017-08-21
      相关资源
      最近更新 更多