页面部分,wxml中写入以下代码
<picker mode = "selector" bindchange="bindPickerChange" value="{{project[idx].id}}" range="{{project}}" range-key="{{‘val‘}}">
<view class="picker picker1">
{{project[idx].val}}<text class=‘down‘></text>
</view>
</picker>
js部分
data: {
idx:0,
project:[
{
id: 0,
val: ‘互联网‘
},
{
id: 1,
val: ‘建材‘
},
{
id: 2,
val: ‘法律‘
},
]
},
// 改变下拉选项
bindPickerChange: function (event){
this.setData({ //给变量赋值
idx: event.detail.value,
})
},
let id = this.data.project[this.data.idx].id
原文地址:https://www.cnblogs.com/isuansuan/p/11698294.html
时间: 2024-10-07 22:57:50