1. 程式人生 > >微信小程式摸索

微信小程式摸索

微信小程式 下拉載入更多 onReachBottom()
重要的是載入商品列表
wxml程式碼
<view wx:for="{{listArr}}" wx:key=''> <view class='colunm11' bindtap='toGoodsDetail' data-goods_id="{{ item.goods_id }}" data-goods_type="{{ item.goods_type }}"> <image src="{{ item.cover_image }}" class='imgy-11'></image> <view class='colunm11-1'> <text id='shangpin'>{{ item.goods_name }}</text> <text id='jiagey'>價格:<text id='biaojia'>¥{{ item.front_show_price }}</text></text> </view> </view> </view>


js程式碼

 getGoods: function() {
    var self = this;
    var baseApiUrl = util.config('baseApiUrl');
    util.ajax({
      url: baseApiUrl + '/api/diary/goods/recommend',
      method: 'GET',
      success: function(res) {
        if (res.status == 1) {
          for (var i in res.lists) {
            listArr.push(res.lists[i]);
          }
          self.setData({
            listArr: listArr,
            goods: res.lists,
          })
        }
      }
    })
  },
  //下拉載入更多
  onReachBottom: function() {
    this.getGoods();
  },