不要沮丧,不必惊慌,做努力爬的蜗牛或坚持飞的笨鸟,我们试着长大,一路跌跌撞撞,然后遍体鳞伤。坚持着,总有一天,你会站在最亮的地方,活成自己曾经渴望的模样。
本文实例为大家分享了微信小程序实现级联菜单的具体代码,供大家参考,具体内容如下
<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 }) },
效果图:
到此这篇关于微信小程序基于picker实现级联菜单就介绍到这了。勇者,必以决斗之勇气与五张试卷一决雌雄;懦夫,概以鼠目之寸光量人生此战必输无疑!更多相关微信小程序基于picker实现级联菜单内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!