本文主要是介绍小程序下拉框,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
页面
<view class="info info-name">
<label class="info-lable">所属街道</label>
<picker bindchange="bindPickerChange2" range-key='{{"cboText"}}' style="float:left; margin-left: 5%" range="{{AreaCode}}">
<view>
<text style="color:#848484">{{AreaCode[qx].cboText}}</text>
</view>
</picker>
</view>
JS
data{
AreaCode: [{
cboValue: '',
cboText: '请选择区县'
}],
selectQA: '',
qx:0
}
onload:function(options)
{
this.GetAreaCode()//调用查询方法
//回填下拉框数值
查询成功后再setData中赋值
this.setData({
selectQA:.areaCode,
})
}
GetAreaCode: function () {
var that = this;
wx.request({
url: app.globalData.ApiPath + 'api/Common/GetComAreaCodeList',
method: 'post',
header: {
'content-type': 'application/json' // 默认值
},
success(res) {
that.setData({
['AreaCode[0].cboValue']: '',
['AreaCode[0].cboText']: '请选择区县'
})
for (var i = 0; i < res.data.length; i++) {
var cboValue = 'AreaCode[' + (i + 1) + '].cboValue';
var cboText = 'AreaCode[' + (i + 1) + '].cboText';
//console.log(cboValue,cboText)
that.setData({
[cboValue]: res.data[i].areaCode,
[cboText]: res.data[i].areaName
})
}
if (that.data.selectQA != "") {
for (let i = 0; i < that.data.AreaCode.length; i++) {
if (that.data.AreaCode[i].cboValue == that.data.selectQA) {
that.setData({
qx: i
})
}
}
}
//console.log(that.data.AreaCode)
}
})
},
//获取下拉框值
bindPickerChange2: function (e) {
//console.log('picker发送选择改变,携带值为', e.detail.value)
var areacode = this.data.AreaCode[e.detail.value].cboValue;
this.setData({
qx: e.detail.value,
selectQA: areacode
})
},
这篇关于小程序下拉框的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!