【问题标题】:How to get value of a ion-select ? My value only appear when I click on the field如何获得离子选择的价值?我的值仅在我单击该字段时出现
【发布时间】:2019-04-15 16:03:19
【问题描述】:

我使用 ionic 开发了一个移动应用程序,但我遇到了 ion-select 标签的问题。 离子选择值似乎没有加载,直到我点击它。

<ion-item>
    <ion-label position="stacked" style="color: darkgrey">Etat intervention {{liste[0].id_etat_intervention}} - {{etat_select}}</ion-label>
    <ion-select okText="OK" cancelText="Annuler" [value]="liste[0].id_etat_intervention">
        <ion-select-option *ngFor="let etat of etats_intervention" [value]="etat.id" >{{etat.id}} {{etat.libelle}}</ion-select-option>
    </ion-select>
</ion-item>

在我的 ts 文件中:

await this.dbProvider.getEtatsIntervention().then((data) => {
    this.etats_intervention = data;
});

在我的提供者文件上:

getEtatsIntervention () {
        const req = 'SELECT id, libelle FROM etat_intervention ORDER BY libelle ASC ;';

        return this.database.executeSql(req, []).then (result => {
            const infos = [];
            if (result.rows.length > 0) {
                for (let i = 0; i < result.rows.length; i++) {
                    infos.push({
                        id: result.rows.item(i).id,
                        libelle: result.rows.item(i).libelle});
                }
            }
            return infos;
        }).catch(e => console.log('erreur database.getEtatsIntervention() ' + e.error));
    }

并且在表单加载时以同样的方式恢复值'liste[0].id_etat_intervention'

这里发生了什么:

When the form is load

When I click on the field

我尝试了所有我被卡住的东西...... 感谢您的帮助!

【问题讨论】:

  • 您可以将列表对象添加到您的问题中吗?
  • 谢谢,我把它放在你的问题中,而不是发布两个答案,这样人们就更容易回答你的问题,也方便以后想参考它的人:)

标签: angular ionic-framework ionic4 ion-select


【解决方案1】:

我找到了解决办法:

<ion-item>
    <ion-label position="stacked" style="color: darkgrey">Etat intervention</ion-label>
    <ion-select okText="OK" cancelText="Annuler" [selectedText]="etat_select" (ionChange)="onChangeEtat($event)">
        <ion-select-option *ngFor="let etat of etats_intervention" [value]="etat.libelle">{{etat.libelle}}</ion-select-option><!-- [value]="etat.id"  -->
    </ion-select>
</ion-item>


onChangeEtat(value) {
    this.etat_select = value.target.value;
}

getEtat() {
    for (const i in this.etats_intervention) {
        if (this.etats_intervention[i].id === this.liste[0].id_etat_intervention) {
            this.etat_select = this.etats_intervention[i].libelle;
        }
    }
}

【讨论】:

    猜你喜欢
    • 2019-09-29
    • 2021-09-10
    • 1970-01-01
    • 2020-06-24
    • 2023-03-24
    • 2018-05-21
    • 2020-02-11
    • 2022-07-31
    • 1970-01-01
    相关资源
    最近更新 更多