177-371-24501(同微信)

用实例讲解微信小程序城市选择器怎么弄?

2022-04-21 管理员

微信小程序开发很重要的一个内容,微信小程序城市选择器的使用,详解微信小程序开发之城市选择器 城市切换,非常具有实用价值,需要的朋友可以参考下。

 

城市选择器 region

//index.wxml
<picker mode="region" bindchange="bindRegionChange" value="{{region}}">
  <view class="picker">
    当前选择:{{region[0]}}{{region[1]}}{{region[2]}}
  view>
picker>

//index.js
data: {
    region: ['广东省', '广州市', '海珠区']
}

多列选择器 multiSelector

  脑残没有关注官方更新,自己写了个城市选择器。

// City.js

//  省份
var provinceList = [
  { "id": "11", "name": "北京", "initial": "B" },
  ...];

var cityList = [
  {
    "provinceId": "11",
    "citys": [
      { "id": "1", "name": "昌平" },
     ...]
  }
];
//  点击省份,获取城市列表
function getCitysById(id) {
  let provinceId = provinceList[id].id;
  var tempObj = [];
  for (let i = 0; i < cityList.length; i++) {
    if (cityList[i].provinceId == provinceId) {
      tempObj = cityList[i].citys;
      break;
    }
  }
  return tempObj;
}

module.exports = {
  provinceList: provinceList,
  getCitysById: getCitysById
}

// Picker.wxml

<picker mode="multiSelector" value="{{index}}" bindcolumnchange="bindPickerChange" range="{{province}}" range-key="{{'name'}}">
  <view class="picker">
    当前选择:{{province[0][0].name}}{{province[1][0].name}}
  view>
picker>

// Picker.js

// picker.js
var cityObj = require("../../utils/city")
Page({
  data: {
    index: 0
  },
  onl oad: function (options) {
    var defaultCitys = cityObj.getCitysById("0")
    this.setData({
      province: [cityObj.provinceList, defaultCitys]
    })
  },
  bindPickerChange(e) {
    if (e.detail.column == 0) {
      var citys = cityObj.getCitysById(e.detail.value);
      this.setData({
        province: [cityObj.provinceList, citys]
      })
    }
  }
})

时间选择器 time

<picker mode="time" value="{{time}}" start="09:01" end="21:01" bindchange="bindTimeChange">
  <view class="picker">
    当前选择: {{time}}
  view>
picker>

日期选择器 date

<picker mode="date" value="{{time}}" start="2015-09-01" end="2017-09-01" fields="month" bindchange="bindTimeChange">
  <view class="picker">
    当前选择: {{time}}
  view>
picker>

rich-text

  • 属性:nodes 类型:Array / String 结点列表 / HTML String
  • 全局支持class和style属性,不支持id属性。
  • 结点类型:type = node  name 标签名 String 是 支持部分受信任的HTML结点  attrs 属性 Object 否 支持部分受信任的属性,遵循Pascal命名法  children 子结点列表 Array 否 结构和nodes一致
  • 结点类型:type = text  text 文本 String 是 支持entities
  • nodes 不推荐使用 String 类型,性能会有所下降
  • rich-text 组件内屏蔽所有结点的事件。
  • attrs 属性不支持 id ,支持 class 。
  • name 属性大小写不敏感。
  • 如果使用了不受信任的HTML结点,该结点及其所有子结点将会被移除。
  • img 标签仅支持网络图片。
<rich-text nodes="{{nodes}}" />
<rich-text nodes="{{nodes1}}" />
<rich-text nodes="{{nodes2}}" />

this.setData({
    nodes: "

html标题

", nodes1: [{ name: "h1", attrs: { style: "color:red", class: "red" }, children: [{ type: "text", text: '结点列表标题' }] }], nodes2: [{ name: "ul", attrs: { style: "padding:20px;border:1px solid blue;", class: "red" }, children: [ { name: "li", attrs: { style: "color:red", class: "red" }, children: [{ type: "text", text: '多层结点 无序列表' }], }, { name: "li", attrs: { style: "color:red", class: "red" }, children: [{ type: "text", text: '多层结点 无序列表1' }], }] }] })
<style type="text/css"> .appreciate{ margin-bottom:16px;} .appreciate .btn_appreciation { display: block; width: 110px; height: 40px; margin: 40px auto 0;font-size: 18px; line-height: 40px; text-align: center; vertical-align: middle; color: #fff; border-radius: 5px; background: #ff8000;} .appreciate .head_count.show { display: block;} .appreciate .head_count {display: none; margin: 30px auto 0; font-size: 14px;text-align: center;} .appreciate .head_count i {color: #ff8000;} .appreciate .head_count b {color: gray;} .appreciate_list_wrapper{ overflow: hidden; margin: 0 auto; width: 200px;} .appreciate_list.vcenter{ text-align: center;} .appreciate_list.vcenter a{ display:block;} .appreciate_list { max-height: 120px; overflow: hidden; margin-right: -6px; line-height: 15px;} .appreciate_list img { position: relative; width: 34px; height: 34px; margin: 0 6px 4px 0; border-radius: 17px;max-width: 100%!important;} .appreciate .btn_appreciation_t{background: #dc5d4a;} .appreciate .head_count_t i {color: #607fa6;} .appreciate_list_wrapper_t{ overflow: hidden; margin: 0 auto; width: 250px;} .appreciate_list_t.vcenter_t { text-align: center;} .appreciate_list_t.vcenter_t a{ display:block;} .appreciate_list_t { max-height: 120px; overflow: hidden; margin-right: -6px; line-height: 15px;} .appreciate_list_t img { position: relative; width: 30px; height: 30px; margin: 0 6px 4px 0;max-width: 100%!important;} </style>
 

上一篇:微信小程序底层的实现原理开发实战说明
下一篇:小程序实例开发只显示群ID 不显示群名称怎么办
相关资讯 Releva ntnews
解决方案 Solutions
相关热点 Hot spot
快速提升网站排名的方法
  1. 我们的优势
  2. 我们的实力
  3. 选择我们的理由
咨询电话(微信同号)

177-371-24501(同微信)

豫ICP备17049932号

Copyright © 2017-2022 版权所有 追风建站 Rights Reserved 技术支持:酷微科技

电话咨询 在线咨询 服务项目 SEO优化