微信小程序基于picker实现级联菜单
程序员文章站
2023-12-09 20:58:45
本文实例为大家分享了微信小程序实现级联菜单的具体代码,供大家参考,具体内容如下
本文实例为大家分享了微信小程序实现级联菜单的具体代码,供大家参考,具体内容如下
<view > <picker bindchange="bindpickerchange0" value="{{brandindex}}" range="{{brands}}"> <view class="picker"> 品牌:{{brands[brandindex]}} </view> </picker> </view> <view > <picker bindchange="bindpickerchange1" value="{{index1}}" range="{{object}}"> <view class="picker"> 配件类别:{{object[index1]}} </view> </picker> </view>
data: { brands: [], objectarray: [ { brand:"博世", id: 0, array: ["博世喷油器配件", "博世传感器", "杰克赛尔配件", "博世油泵配件", "博世共轨管配件","博世泵喷嘴"] }, { brand: "德尔福", id: 1, array: ["德尔福喷油器配件", "德尔福传感器", "德尔福油泵", "德尔福共轨管配件", "德尔福滤清器", "德尔福电脑版ecu", "德尔福机油", "德尔福维修部件"] }, { brand: "卡特", id: 2, array: ["卡特传感器", "卡特c7c9泵喷嘴","卡特共轨配件"] }, { brand: "康明斯", id: 3, array: ["西康配件", "东风康明斯","福田康明斯"] } ], object:[], brandindex:0, index1:0 }, onload:function(){ var objectarray = this.data.objectarray var brands=[] for (var i = 0; i < objectarray.length;i++){ brands.push(objectarray[i].brand,) } this.setdata({ brands: brands ,object: objectarray[this.data.brandindex].array}) }, bindpickerchange0: function (e) { this.setdata({ brandindex: e.detail.value, index1:0 }) var objectarray = this.data.objectarray this.setdata({ object: objectarray[this.data.brandindex].array}) }, bindpickerchange1: function (e) { this.setdata({ index1: e.detail.value }) },
效果图:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。