html
<picker bindchange="bindPickerChanges" value="{{selectedIndex}}"
range="{{pickerArray}}"
range-key="name">
<view class="area-select">在线状态:
<label for="">{{pickerArray[selectedIndex].name}}</label>
<image src="/img/arrow_down.png"></image>
</view>
</picker>
page{
data{
pickerArray: [{
value: 0,
name: '全部'
},{
value: 1,
name: '在线'
}, {
value: 2,
name: '离线'
}],
selectedIndex: 0,
}
}
html
//点击事件
bindPickerChanges: function(e) {
this.setData({
selectedIndex : e.detail.value,
'query.netStatus': this.data.pickerArray[e.detail.value].value
});
this.onSearch();
},
返回主页面时需要将下拉的name值进行匹配,重新刷新
下拉的状态值: 'query.netStatus'
html
onShow: function () {
let pages = getCurrentPages();
let currPage = pages[pages.length - 1]; //当前页面
let districtName = currPage.data.districtName;
let indexData = currPage.data.indexData;
let districtCode = currPage.data.districtCode;
let netStatus = currPage.data.netStatus;
// debugger
// debugger
this.setData({
'query.page': 1,
'query.districtCode': districtCode || 0,
deviceList: [],
pickAll: false,
districtName,
indexData,
'query.netStatus': this.data.pickerArray.find(it=>it.name==this.data.pickerArray[this.data.selectedIndex].name).value,
'query.operationType': app.globalData.operationType
})
this.getAllDeviceAll();
wx.stopPullDownRefresh();
this.setLanguage();
},