微信小程序的联系人列表

710 阅读1分钟
  • 需求: 模仿手机联系人列表的功能
  • 基本思路: scroll-view主体,绝对定位有侧边栏
  • 坑:
    • 1.scroll-view有scroll,每次滚动触发,需要节流
    • 2.跳转会延迟,跟随延迟:setData(网上说最好不要用它绑定视图数据) android特别难受 -- 不知道怎么解决,尝试过获取列表高度,利用高度的对比,但还是需要与视图绑定一个 currentIndex, 表示目前的位置
  • 小点: 微信小程序节流函数绑定
    const debounce = function (fn, gapTime) {
      if (gapTime == null || gapTime == undefined) {
        gapTime = 1500
      }
      let _lastTime = null // 返回新的函数 
        return function () {
          let _nowTime = + new Date()
          if (_nowTime - _lastTime > gapTime || !_lastTime) {
            fn.apply(this, arguments)   //将this和参数传给原函数
            _lastTime = _nowTime
          }
      }
    }
    // page外声明一个节流函数
    // tip: 普通节流函数不会传入event和this参数
    scroll: debounce(function (e) {}, 500)