angular - ion-select - 确定单击列表未正确显示
问题描述
我正在实施第一次运行良好的离子选择。当我们第二次选择下拉菜单时,这次只显示之前选择的值。任何人都可以知道如何解决这个问题吗?
<div>
<ion-select [(ngModel)]="countryList" multiple="true" (cancel)="onCancel()" (change)="onSelectChange($event)">
<ion-option *ngFor="let country of countryList" >{{country}}</ion-option>
</ion-select>
</div>
下拉框第一次显示了印度、斯里兰卡、意大利、德国、法国等国家。
如果我选择意大利和印度并单击确定,剩余的国家会自动从列表中消失。如果我们下次单击,则仅显示意大利和印度。其余国家被删除。
上面的代码需要任何更改来解决这个问题吗?
解决方案
您countryList
的设置为ngModel
您的选择,表示双向绑定。一旦您第一次选择任何值,您的列表就会发生变化。你需要一个selectedCountries
列表来保存你的价值观。
<div>
<ion-select [(ngModel)]="selectedCountries" multiple="true" (cancel)="onCancel()" (change)="onSelectChange($event)">
<ion-option *ngFor="let country of countryList" >{{country}}</ion-option>
</ion-select>
</div>
在 ts 中声明变量。
selectedCountries:any;
推荐阅读
- javascript - 从异步函数获取 e.target 值的问题
- python - 在 jupyter notebook 上导入 csv 数据的问题
- swift - 我们如何获得上一行和下一行的范围?
- python - 如何比较两个列表以保持匹配的子字符串以及如何保留基于子字符串的顺序?
- sql - SQL:检测具有相同键的连续行的连续块
- css - 如何应用纵横比媒体查询
- azure - Azure 数据工厂错误:“附近有不正确的语法”
- python - 如何将模型的输入张量传递给损失函数?
- firebase - 允许未经身份验证的用户写入 Firestore
- flutter - Flutter如何按条件过滤数组