如何获得离子选择的价值?我的价值仅在我单击该字段时出现

时间:2019-04-10 09:34:20

标签: angular ionic-framework ionic4 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

我尝试了所有遇到的困难... 谢谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我找到了解决方法:

<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;
        }
    }
}