例
在HTML中
<ion-item inset>
<ion-label floating i18n>Gotram*</ion-label>
<ion-input type="text" (focus)="selectGotram()" readonly [(ngModel)]="user.gotram" name="gotram" #gotram="ngModel" required></ion-input>
</ion-item>
Run Code Online (Sandbox Code Playgroud)
在组件中
selectGotram() {
let data = { "title": "Gotram", "form": "show_autocomplete", "data": gotrams }
let modal = this.modalCtrl.create(HelperComponent, data);
modal.onDidDismiss(data => {
if (data) {
this.user.gotram = data;
}
});
modal.present();
}
Run Code Online (Sandbox Code Playgroud)
在辅助组件模态html中
<ion-searchbar showCancelButton="true" (ionInput)="getItems($event)" (ionCancel)="clearItems($event)"></ion-searchbar>
<ion-list radio-group [(ngModel)]="selected_item">
<ion-item *ngFor="let item of data" (click)="selectedItem(item)">
<ion-label>{{item}}</ion-label>
<ion-radio [value]="item"></ion-radio>
</ion-item>
<ion-item *ngIf="data?.length ==0">
<h2>no matched items</h2>
</ion-item>
</ion-list>
Run Code Online (Sandbox Code Playgroud)
在辅助组件模态中
this.data = this.params.get('data');
this.auto_complete = this.data;
getItems(ev) {
// set val to the value of the ev target
var val = ev.target.value;
console.log(val);
// if the value is an empty string don't filter the items
if (val && val.trim() != '') {
this.data = this.auto_complete.filter((item) => {
return (item.toLowerCase().indexOf(val.toLowerCase()) > -1);
})
}
console.log(this.data);
}
clearItems(ev) {
// set val to the value of the ev target
var val = ev.target.value;
console.log(val);
// if the value is an empty string don't filter the items
if (val && val.trim() != '') {
this.data = this.auto_complete.filter((item) => {
return (item.toLowerCase().indexOf(val.toLowerCase()) > -1);
})
}
}
selectedItem(item) {
this.viewCtrl.dismiss(item);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13979 次 |
| 最近记录: |