/* ---html----*/
 
<ion-searchbar [(ngModel)]="searchQuery" (input)="getItems($event)"></ion-searchbar>
<ion-list>
  <ion-item *ngFor="#item of items">
    {{ item }}
  </ion-item>
</ion-list>
 
/* ---html----*/
/* ---js----*/
 
import {Page} from 'ionic-angular';
 
@Page({
  templateUrl: 'build/pages/tabs/tabs.html',
})
 
export class TabsPage {
 
  constructor() {
    this.searchQuery = '';
    this.initializeItems();
  }
 
  initializeItems() {
    this.items = [
      'Amsterdam',
      'Bogota',
    ];
  }
 
  getItems(searchbar) {
    //给作用域 items 一个默认值。
    this.initializeItems();
    //获取文本框里的 value
    var q = searchbar.value;
 
    //如果值是空字符串,则不过滤项目
    if (q.trim() == '') {
      return;
    }
    //否则 过滤一下 this.items
    this.items = this.items.filter((v) => {
      if (v.toLowerCase().indexOf(q.toLowerCase()) > -1) {
        return true;
      }
      return false;
    })
  }
 
}
 
/* ---js----*/

9、搜索 :ion-searchbar

还有更多的样式http://ionicframework.com/docs/v2/api/components/searchbar/Searchbar/

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-30
  • 2021-12-19
  • 2021-05-09
  • 2022-02-07
  • 2021-05-08
  • 2021-04-20
猜你喜欢
  • 2022-12-23
  • 2021-06-01
  • 2021-12-04
  • 2021-12-27
  • 2022-12-23
  • 2021-06-08
  • 2021-12-20
相关资源
相似解决方案