zoukankan      html  css  js  c++  java
  • antd省市区级联

    import React, { useState } from 'react'
    import { Cascader } from 'antd'
    import options from '../../utils/cities'
    
    export default function AreaCascader({ value = [], onChange, getPopupContainer }) {
      const [cascader, setCascader] = useState([])
      
      const handleChange = (value, list) => {
        onChange(value)
        console.log(value)
        setCascader(value)
        console.log(list)
      }
    
      return (
        <div>
          <Cascader
            value={value || cascader}
            options={options}
            fieldNames={{value: 'code'}}
            onChange={handleChange}
            placeholder="选择所属城市"
            style={{  300 }}
            getPopupContainer={getPopupContainer}
          />
        </div>
      )
    }
    

    //根据省市区编码查询省市区
    const findAreaText = (location) => {
      let result = []
      for (let i = 0; i < areaOptions.length; i++) {
        if (areaOptions[i].code === location[0] + '') {
          result.push(areaOptions[i].label)
        }
        for (let j = 0; j < areaOptions[i].children.length; j++) {
          if (areaOptions[i].children[j].code === location[1] + '') {
            result.push(areaOptions[i].children[j].label)
          }
          if (Array.isArray(areaOptions[i].children[j].children)) {
            for (let z = 0; z < areaOptions[i].children[j].children.length; z++) {
              if (
                areaOptions[i].children[j].children[z].code ===
                location[2] + ''
              ) {
                result.push(areaOptions[i].children[j].children[z].label)
              }
            }
          }
        }
      }
      return result
    }
    

    数据来源:https://github.com/heerey525/antdCascaderDate/blob/master/src/cities.js

    https://github.com/heerey525/antdCascaderDate

  • 相关阅读:
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    剑指offer-栈的压入、弹出序列
    剑指offer-包含min函数的栈
    图-Dijkster最短路径
    剑指offer-顺时针打印矩阵
    二叉树的镜像
    剑指offer-树的子结构
  • 原文地址:https://www.cnblogs.com/xutongbao/p/15264339.html
Copyright © 2011-2022 走看看