zoukankan      html  css  js  c++  java
  • 微信小程序自定义Searchbar取消事件

    其实我们主要是想实现点击取消的时候直接隐藏Searchbar,但目前的取消是仅把input框重置了。

    不知道为啥微信小程序的Searchbar没有允许直接bindcancel事件,在微信社区找到答案需要自己重写后才行。

      /** searchBar 部分 */
      reSetSearchbarCancel() {
        let sbar = this.selectComponent("#或.你的searchbar"), { hideInput } = sbar;
        // 重写
        Object.defineProperties(sbar.__proto__, {
          hideInput: {
            configurable: true,
            enumerable: true,
            writable: true,
            value(...p) {
              // 加上这句,同时wxml需要加上bindcancel="cancel"
              this.triggerEvent('cancelSearchbar', {})
              // 或者这里直接调用下面的cancel方法,那么wxml就不需要bindcancel
              // t.cancel()
              // 执行原方法,返回原方法结果
              return hideInput.apply(sbar, p)
            }
          }
        })
      },
      cancelSearchbar() {
       // 执行你的操作
        this.setData({
          show_minzu: false
        })
      },
  • 相关阅读:
    Redis
    元类 metaclass
    聊一聊 Django 中间件
    Django rest framework
    聊一聊python的单例模式
    Django-admin管理工具
    MongoDB
    Beautifulsoup
    三、模型(一)
    九、Python发送QQ邮件(SMTP)
  • 原文地址:https://www.cnblogs.com/jying/p/15323245.html
Copyright © 2011-2022 走看看