test(searchbar): added some code to the searchbar nav test based on the docs

This commit is contained in:
Brandy Carney
2016-01-05 19:48:19 -05:00
parent bd12571a1a
commit ff0693fe65
2 changed files with 71 additions and 2 deletions

View File

@ -17,7 +17,72 @@ class FirstPage {
templateUrl: 'second.html'
})
class SecondPage {
constructor() {
this.searchQuery = '';
this.initializeItems();
}
initializeItems() {
this.items = [
'Amsterdam',
'Bogota',
'Buenos Aires',
'Cairo',
'Dhaka',
'Edinburgh',
'Geneva',
'Genoa',
'Glasglow',
'Hanoi',
'Hong Kong',
'Islamabad',
'Istanbul',
'Jakarta',
'Kiel',
'Kyoto',
'Le Havre',
'Lebanon',
'Lhasa',
'Lima',
'London',
'Los Angeles',
'Madrid',
'Manila',
'New York',
'Olympia',
'Oslo',
'Panama City',
'Peking',
'Philadelphia',
'San Francisco',
'Seoul',
'Taipeh',
'Tel Aviv',
'Tokio',
'Uelzen',
'Washington'
];
}
getItems(searchbar) {
// Reset items back to all of the items
this.initializeItems();
// set q to the value of the searchbar
var q = searchbar.value;
// if the value is an empty string don't filter the items
if (q.trim() == '') {
return;
}
this.items = this.items.filter((v) => {
if (v.toLowerCase().indexOf(q.toLowerCase()) > -1) {
return true;
}
return false;
})
}
}
@App({

View File

@ -8,6 +8,10 @@
</ion-toolbar>
<ion-content>
<ion-searchbar primary placeholder="Filter Schedules">
</ion-searchbar>
<ion-searchbar [(ngModel)]="searchQuery" (input)="getItems($event)"></ion-searchbar>
<ion-list>
<ion-item *ngFor="#item of items">
{{ item }}
</ion-item>
</ion-list>
</ion-content>