Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the City Selector in WeChat Mini Programs's Development

Shulou Source: shulou.com Published: 2022-05-31 21:50:11 09月21日 Update

In this article, the editor introduces in detail "how to realize the city selector in the development of WeChat Mini Programs". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to realize the city selector in the development of WeChat Mini Programs" can help you solve your doubts. Let's follow the editor's ideas to learn new knowledge.

City selector is essential in mobile development.

Gif:

Here is only part of the js code:

Var city = require ('.. /.. / utils/city.js'); Page ({data: {searchLetter: [], showLetter: ", winHeight: 0, tHeight: 0, bHeight: 0, startPageY: 0, cityList: [], isShowLetter: false, scrollTop: 0, city:"}, onLoad: function (options) {/ / Lifecycle function-load var searchLetter = city.searchLetter; var cityList = city.cityList () / / console.log (cityInfo); var sysInfo = wx.getSystemInfoSync (); console.log (sysInfo); var winHeight = sysInfo.windowHeight; / / add the letter range value / / 1 to match, more screen height setting the height of child elements 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 }) console.log(this.data.cityInfo); }, onReady: function () { // 生命周期函数--监听页面初次渲染完成 }, onShow: function () { // 生命周期函数--监听页面显示 }, onHide: function () { // 生命周期函数--监听页面隐藏 }, onUnload: function () { // 生命周期函数--监听页面卸载 }, onPullDownRefresh: function () { // 页面相关事件处理函数--监听用户下拉动作 }, onReachBottom: function () { // 页面上拉触底事件的处理函数 }, onShareAppMessage: function () { // 用户点击右上角分享 return { title: 'title', // 分享标题 desc: 'desc', // 分享描述 path: 'path' // 分享路径 } }, searchStart: function (e) { var showLetter = e.currentTarget.dataset.letter; var pageY = e.touches[0].pageY; this.setScrollTop(this, showLetter); this.nowLetter(pageY, this); this.setData({ showLetter: showLetter, startPageY: pageY, isShowLetter: true, }) }, searchMove: function (e) { var pageY = e.touches[0].pageY; var startPageY = this.data.startPageY; var tHeight = this.data.tHeight; var bHeight = this.data.bHeight; var showLetter = 0; console.log(pageY); if (startPageY - pageY >

0) {/ / move if up (pageY

< tHeight) { // showLetter=this.mateLetter(pageY,this); this.nowLetter(pageY, this); } } else {//向下移动 if (pageY >

BHeight) {/ / showLetter=this.mateLetter (pageY,this); this.nowLetter (pageY,this);}, searchEnd: function (e) {/ / console.log (e); / / var showLetter=e.currentTarget.dataset.letter; var that = this; setTimeout (function () {that.setData ({isShowLetter: false})}, 1000)}, nowLetter: function (pageY, that) {/ / currently selected information var letterData = this.data.searchLetter Var bHeight = 0; var tHeight = 0; var showLetter = ""; for (var I = 0; I < letterData.length; iTunes +) {if (letterdata [I] .tHeight)

Tags: Development selection city path article content height mobility appropriateness code information elements functions cycles periodic functions letters screens essentials ideas new knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Docker Apple Redmi Linux