【发布时间】:2018-07-21 15:05:09
【问题描述】:
您好,请帮助我正在尝试从列表中进行搜索,单词显示在列表中,但清除搜索栏后没有显示任何内容,请帮助
这是我的 home.html
<ion-searchbar (ionInput)="getItems($event)"[showCancelButton]="shouldShowCancel" (ionCancel)="onCancel($event)"></ion-searchbar>
</ion-header>
<ion-content padding>
<ion-list>
<button ion-item *ngFor="let item of items" (click)="eXplain()">
{{ item.word }}
</button>
</ion-list>
</ion-content>
而我的 home.ts 是:
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
searchQuery: string = '';
items:any;
word:any;
meaning:any;
constructor(public navCtrl: NavController, private http: Http, public alertCtrl: AlertController, public loading: LoadingController,public modalCtrl : ModalController) {
this.initializeItems();
}
ngOnInit(){
var headers = new Headers();
headers.append("Accept", 'application/json');
headers.append('Content-Type', 'application/json' );
let options = new RequestOptions({ headers: headers });
let loader = this.loading.create({
content: 'Processing please wait...',
});
loader.present().then(() => {
this.http.post('**MY URL IS HERE**',options)
.map(res => res.json())
.subscribe(res => {
loader.dismiss()
this.items=res.server_response;
console.log(this.items);
});
});
}
initializeItems() {
this.items;
}
getItems(ev) {
// Reset items back to all of the items
this.initializeItems();
// 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: any) => {
return (item.word.toLowerCase().indexOf(val.toLowerCase()) > -1);
})
}
}
}
单词显示在列表中,但清除搜索栏后未显示任何内容,请帮助
【问题讨论】:
-
@Golden Mashego 你没有返回任何物品,如果输入值为空,你应该返回所有物品
-
感谢回复,我还是 ionic 新手,该怎么做?
标签: angular search ionic-framework ionic2 ionic3