【发布时间】:2022-01-20 20:57:32
【问题描述】:
我想在 ionic 中获取我的自定义数据属性的值。我尝试了很多方法,但没有一个对我有用。这是我的离子选择:
<ion-item>
<ion-select value="اصفهان" (ionChange)="getCities($event)" [(ngModel)]="model.united" [ngModelOptions]="{standalone: true}" ok-text="تایید" cancel-text="کنسل">
<ion-select-option value="{{item.name}}" data-id="{{item.id}}" *ngFor="let item of provinces">{{item.name}}</ion-select-option>
</ion-select>
</ion-item>
我想在我的方法中获取 'data-id'。这是方法:
getCities($event) {
const provinceId= $event.target.getAttribute('data-id');
}
但它返回 null。我该怎么办?
【问题讨论】: