• 微信小程序开发之带搜索记录的搜索框


    实现功能:点击搜索框,有搜索记录时以下拉菜单显示,点击下拉子菜单,将数据赋值到搜索框,点击搜索图标搜索,支持清空历史记录,可手动输入和清空查询关键字,

    UI:

    wxml:


    <!--查询历史记录数据-->
    <view class="ddclass" style="margin-left: 50rpx;z-index:80" hidden="{{!StorageFlag}}" style="z-index:100">
      <view wx:for="{{sercherStorage}}" wx:key="item.id">
        <view class="liclass" style="color:#ec9e14;border-bottom:0;" id="{{item.id}}" bindtap="tapSercherStorage">
          <text style="100rpx">{{item.name}}</text>
        </view>
      </view>
      <view wx:if="{{sercherStorage.length!==0}}" style="text-align:center;" bindtap="clearSearchStorage">
        <text style="text-align:center;color:red;font-size:28rpx">清空历史记录</text>
      </view>
    </view>

    wxss:

    /*二级菜单外部容器样式*/
       .ddclass {
     position: absolute;
      100%;
     margin-top: 10px;
     left: 0;
     
    }

     
    /*二级菜单普通样式*/
     
     .liclass {
     font-size: 14px;
     line-height: 34px;
     color: #575757;
     height: 34px;
     display: block;
     padding-left: 18px;
     background-color: #fff;
     border-bottom: 1px solid #dbdbdb;
    }
     
    /*二级菜单高亮样式*/
     
     li.highlight {
     background-color: #f4f4f4;
     color: #48c23d;
    }

    js:

    data:{

    sercherStorage: [],  

    inputValue: "",             //搜索框输入的值  

    StorageFlag: false,         //显示搜索记录标志位

    }

      //获取输入框的输入信息
      bindInput: function (e) {
        this.setData({
          inputValue: e.detail.value
        })
      },

     //清楚输入框数据
      clearInput:function(){
        this.setData({
          inputValue: ""
        })
      },
      //清楚缓存历史并关闭历史搜索框
      clearSearchStorage: function () {
        wx.removeStorageSync('searchData')
        this.setData({ sercherStorage: [],
          StorageFlag: false,  })
      },
      //点击缓存搜索列表
      tapSercherStorage:function(e)
    {
        var that = this;
        var index = parseInt(e.currentTarget.id);
        for (var j = 0; j < that.data.sercherStorage.length; j++) {
          if (j == index) {
            //将所选的搜索历史加到搜素框
            this.setData({
              inputValue: that.data.sercherStorage[j].name,
              StorageFlag: false,   
            })
          }}
        if (this.data.inputValue != '') {
        //请求搜索记录
        }

    },  
    //打开历史记录列表
      openLocationsercher:function(e)
      {
        this.setData({
          sercherStorage: wx.getStorageSync('searchData') || [],   //调用API从本地缓存中获取数据
          StorageFlag: true,
          listFlag: true,
        })
      },
    //添加搜索记录并搜索
      setSearchStorage: function () {
        //let data;
        var that=this;
      //let localStorageValue = [];
        if (this.data.inputValue != '') {
          //将搜索记录更新到缓存
          var searchData = that.data.sercherStorage;
          searchData.push({
            id: searchData.length,
            name: that.data.inputValue})
          wx.setStorageSync('searchData', searchData);
          that.setData({ StorageFlag: false,})
          
          //请求搜索
          /*wx.request({
            url: '',
            data: {SercherValue:that.data.inputValue,
                SercherTypeNum:that.data.SercherTypeNum,
                typeItem:that.data.typeItem },
            header: {},
            method: '',
            dataType: '',
            success: function(res) {},
            fail: function(res) {},
            complete: function(res) {},
          })*/
          //wx.navigateTo({
          //  url: '../result/result'
         // })
          // console.log('马上就要跳转了!')
        } else {
          console.log('空白的你搜个jb')
        }
        // this.onLoad();
      },

  • 相关阅读:
    5.scala中的对象
    4.scala中的类
    第八章 前端框架
    第六章 用户管理
    第五章 权限验证
    第四章 功能初始化
    第三章 项目结构
    第二章 基于二进制进行权限管理的理论知识
    第一章 权限管理DEMO简介
    NopCommerce源代码分析之用户验证和权限管理
  • 原文地址:https://www.cnblogs.com/min-min-min/p/7452916.html
Copyright © 2020-2023  润新知