javascript - 更改对象阵列后, ionic 选择选项不会刷新

标签 javascript angular ionic-framework ionic4

我有 2 个 ionic 选择 当第一个更改时,第二个应该更新

我已经在第一个上设置了(ngModelChange) 我更改了第二个中显示的元素数组 但这行不通 请帮忙

<ion-item text-right>
    <ion-select
            interface="alert"
            [interfaceOptions]="receiveDatesOptions"
            [compareWith]="compareWithDates"
            [(ngModel)]="receiveDate"
            (ngModelChange)="changedReceiveDate()"
            [selectedText]="receiveDate.datePersian">
        <ion-select-option
                *ngFor="let date of currentReceiveDates"
                [value]="date">{{date.datePersian}}
        </ion-select-option>
    </ion-select>
</ion-item>


<ion-item text-right>
    <ion-select
            interface="alert"
            (ngModelChange)="changeDeliveredDate()"
            [interfaceOptions]="deliverDatesOptions"
            [compareWith]="compareWithDates"
            [(ngModel)]="deliverDate"
            [selectedText]="deliverDate.datePersian">
        <ion-select-option
                *ngFor="let date of currentDeliverDates"
                [value]="date">{{date.datePersian}}
        </ion-select-option>
    </ion-select>
</ion-item>
    changedReceiveDate() {
        this.receiveTimes = this.receiveDate.parts;
        this.currentDeliverDates.splice(0, 2);
        // even if set it to an empty array it wont help
    }

我预计第二个选择的项目会越来越少,但我不会改变 即使我将其设置为空数组

最佳答案

检查此链接。我想你也有同样的问题。

https://forum.ionicframework.com/t/ionic-4-ion-select-option-underlying-list-not-updating/158251

https://github.com/ionic-team/ionic/issues/16453

现在尝试更改您的第二个选择项目代码,使其正常工作。

<ion-item text-right *ngIf="refreshed">
     <ion-select
        interface="alert"
        (ngModelChange)="changeDeliveredDate()"
        [interfaceOptions]="deliverDatesOptions"
        [compareWith]="compareWithDates"
        [(ngModel)]="deliverDate"
        [selectedText]="deliverDate.datePersian">
    <ion-select-option
            *ngFor="let date of currentDeliverDates"
            [value]="date">{{date.datePersian}}
    </ion-select-option>
   </ion-select>
</ion-item>

changedReceiveDate() {
    this.refreshed = false;
    this.receiveTimes = this.receiveDate.parts;
    this.currentDeliverDates.splice(0, 2);
    setTimeout(()=>{
        this.refreshed = true;
    })

}

关于javascript - 更改对象阵列后, ionic 选择选项不会刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57727662/

相关文章:

javascript - 如何使用 JavaScript 从字符串中删除重复的 CSS 样式?

javascript - 如何使图像蒙版出现在悬停时

angular - typescript 类型 BeforeInstallPromptEvent

angularjs - ionic + android 后退按钮 + sidemenu isOpen 检测 - 工作不可靠

authentication - 原始异常 : No provider for Auth!:Ionic 云服务

javascript - 在 ComponentDidMount 中赋值,而不是 React 中的构造函数

javascript - 为什么我无法从 ajax post 请求中获取操作

angular - 为什么 http 请求响应不以 Angular 2 显示?

javascript - 将鼠标悬停在所有列表项上,指定项除外

javascript - 无法创建IONIC项目