9、搜索 :ion-searchbar

/* ---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----*/

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

转载于:https://www.cnblogs.com/dandingjun/p/5562528.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值