微信小程序 scroll-view滚动到索引位置

 

<scroll-view scroll-y="true" scroll-into-view="{{toView}}">  
  <view class="brand" wx:for="{{brandList}}">  
    <view class="line"></view>  
    <view id="{{item.wordindex}}" class="wordindex">{{item.wordindex}}</view>  
    <view class="line"></view>  
    <view class="brand_block">  
      <view class="color_view" wx:for="{{item.brand}}" bindtap="click">  
        <image src="{{item.brandimg}}"></image>  
      </view>  
    </view>  
  </view>  
</scroll-view>  
<view class="index">  
  <text wx:for="{{wordindex}}" bindtap="choiceWordindex" data-wordindex="{{item.wordindex}}">  
    {{item.wordindex}}  
  </text>  
</view>  
// pages/order/car/add_car/car_brand/car_brand.js  
var app = getApp()  
Page({  
  data: {  
    "brandList": [],  
    "wordindex": [],  
    "toView": '#',  
  
  },  
  onLoad: function (options) {  
    var that = this;  
    // 页面初始化 options为页面跳转所带来的参数  
    app.func.req('getCarBrand?cx=1', function (res) {  
      if (res.data.result == 'false') {  
        console.log('false');  
        that.wetoast.toast({  
          title: res.data.msg,  
          duration: 2000  
        })  
      } else {  
        that.setData({  
          brandList: res.data.brandList,  
          wordindex: res.data.brandList,  
        });  
        var cData = that.data.brandList;  
        cData[0].wordindex = "#";//先修改json值  
        that.setData({ //再set值  
          wordindex: cData  
        })  
      }  
    }, function (res) {  
  
    });  
  
  },  
  onReady: function () {  
    // 页面渲染完成  
  },  
  onShow: function () {  
    // 页面显示  
  },  
  onHide: function () {  
    // 页面隐藏  
  },  
  onUnload: function () {  
    // 页面关闭  
  },  
  click: function () {  
    wx.navigateTo({  
      url: '/pages/order/car/add_car/car_model/car_model',  
    })  
  },  
  choiceWordindex: function (event) {  
    let wordindex = event.currentTarget.dataset.wordindex;  
    if (wordindex == '#') {  
      this.setData({  
        toView: '常用品牌',  
      })  
    } else {  
      this.setData({  
        toView: wordindex,  
      })  
    }  
  
    console.log(this.data.toView);  
  }  
})  

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值