您好,登錄后才能下訂單哦!
本文實(shí)例為大家分享了微信小程序城市選擇器,供大家參考,具體內(nèi)容如下
代碼很簡單.
var city = require('../../utils/city.js'); var app = getApp() Page({ data: { searchLetter: [], showLetter: "", winHeight: 0, // tHeight: 0, // bHeight: 0, cityList: [], isShowLetter: false, scrollTop: 0,//置頂高度 scrollTopId: '',//置頂id city: "上海市", hotcityList: [{ cityCode: 110000, city: '北京市' }, { cityCode: 310000, city: '上海市' }, { cityCode: 440100, city: '廣州市' }, { cityCode: 440300, city: '深圳市' }, { cityCode: 330100, city: '杭州市' }, { cityCode: 320100, city: '南京市' }, { cityCode: 420100, city: '武漢市' }, { cityCode: 410100, city: '鄭州市' }, { cityCode: 120000, city: '天津市' }, { cityCode: 610100, city: '西安市' }, { cityCode: 510100, city: '成都市' }, { cityCode: 500000, city: '重慶市' }] }, onLoad: function () { // 生命周期函數(shù)--監(jiān)聽頁面加載 var searchLetter = city.searchLetter; var cityList = city.cityList(); var sysInfo = wx.getSystemInfoSync(); var winHeight = sysInfo.windowHeight; var itemH = winHeight / searchLetter.length; var tempObj = []; for (var i = 0; i < searchLetter.length; i++) { var temp = {}; temp.name = searchLetter[i]; temp.tHeight = i * itemH; temp.bHeight = (i + 1) * itemH; tempObj.push(temp) } this.setData({ winHeight: winHeight, itemH: itemH, searchLetter: tempObj, cityList: cityList }) }, onReady: function () { // 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成 }, onShow: function () { // 生命周期函數(shù)--監(jiān)聽頁面顯示 }, onHide: function () { // 生命周期函數(shù)--監(jiān)聽頁面隱藏 }, onUnload: function () { // 生命周期函數(shù)--監(jiān)聽頁面卸載 }, onPullDownRefresh: function () { // 頁面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動作 }, onReachBottom: function () { // 頁面上拉觸底事件的處理函數(shù) }, clickLetter: function (e) { console.log(e.currentTarget.dataset.letter) var showLetter = e.currentTarget.dataset.letter; this.setData({ showLetter: showLetter, isShowLetter: true, scrollTopId: showLetter, }) var that = this; setTimeout(function () { that.setData({ isShowLetter: false }) }, 1000) }, //選擇城市 bindCity: function (e) { console.log("bindCity") this.setData({ city: e.currentTarget.dataset.city }) }, //選擇熱門城市 bindHotCity: function (e) { console.log("bindHotCity") this.setData({ city: e.currentTarget.dataset.city }) }, //點(diǎn)擊熱門城市回到頂部 hotCity: function () { this.setData({ scrollTop: 0, }) } })
demo下載地址
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。