小程序搜索功能(选择国家地区)

本文介绍了如何在小程序中实现搜索功能,并且详细讲解了如何集成国家和地区的选择,让用户能根据地理位置进行定制化的搜索体验。内容涵盖前端开发中的组件设计、API调用以及数据处理等关键点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!--  搜索框  -->
<view class='search'>
    <image class="" src='../../images/search.jpg'></image>
    <input type='text' placeholder='请输入您想要的内容' confirm-type='search' value="{{inputValue}}" bindinput='inputBind'></input>

</view>
 //搜索框文本内容显示
  inputBind: function (event) {
    this.setData({
      inputValue: event.detail.value
    })
    console.log('bindInput' + this.data.inputValue)
    this.query();
  },
data: {
    show1: '',
    show: '',
    shows: '',
    showJsonList: [],
    checkPage: '',
    inputValue: '', //搜索的内容
    // currentTab: 0
    result: [],
    isShow: false,
    toView: ''
  },

/**
   * 搜索执行按钮
   */
  query: function () {
    if (this.data.inputValue == '') {
      this.setData({
        isShow: false
      })
      return;
    }
    console.log(this.data.inputValue, ' this.data.result');
    var that = this
    that.setData({
      result: [],
      isShow: true
    })
    var val = [];
    console.log(this.data.inputValue, ' this');
    for (var i = 1; i < this.data.showJsonList.length; i++) {
      for (var j = 0; j < this.data.showJsonList[i].data.length; j++) {

        var searchTitle = this.data.showJsonList[i].data[j].chinese_name;
        if (searchTitle.indexOf(this.data.inputValue) != -1) {
          val.push(this.data.showJsonList[i].data[j])

          // this.data.result.push( this.data.showJsonList[i].data[j]);
          // console.log(val, 'val');

        }
      }
    }
    that.setData({
      result: val
    })


  },

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值