0
我將正確的數據傳遞給this.items,但切換到視圖後不會出現,此時通常應該觸發ionViewWillEnter方法。相反,它打字的東西進入我的搜索欄ionViewWillEnter不會觸發(離子2,角2,打字稿)
ionViewWillEnter方法後的作用:
ionViewWillEnter() {
...
this.http.post('http://www.example.com/select.php', creds, {
headers: headers
})
.map(res => res.json().User)
.subscribe(
data => this.data = data.map(user => user.Name),
err => this.logError(err),
() => console.log('Completed')
);
this.items = this.data;
}
搜索欄:
getItems(ev) {
// Reset items back to all of the items
this.initializeItems(); // same code as ionViewWillEnter
// set val to the value of the ev target
var val = ev.target.value;
// if the value is an empty string don't filter the items
if (val && val.trim() != '') {
this.items = this.items.filter((item) => {
return (item.toLowerCase().indexOf(val.toLowerCase()) > -1);
})
}
}
我的html:提前
<ion-searchbar (ionInput)="getItems($event)"> </ion-searchbar>
<ion-list>
<ion-item *ngFor="let item of items">
{{ item }}
...
感謝和問候