JSPM

region-tree-data

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q33632F
  • License ISC

Package Exports

  • region-tree-data

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (region-tree-data) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

region-tree-data

region-tree-data 最新中国区域编码级联数据

安装

npm install region-tree-data

yarn add region-tree-data

使用

参照element-china-area-data

import {setData, getByArea, provinceAndCityData, regionData, provinceAndCityDataPlus, regionDataPlus, CodeToText, TextToCode } from 'region-tree-data'

let {setData, getByArea, provinceAndCityData, regionData, provinceAndCityDataPlus, regionDataPlus, CodeToText, TextToCode } = require('region-tree-data')
  1. provinceAndCityData是省市二级联动数据(不带“全部”选项)
  2. regionData是省市区三级联动数据(不带“全部”选项)
  3. provinceAndCityDataPlus是省市区三级联动数据(带“全部”选项)
  4. regionDataPlus是省市区三级联动数据(带“全部”选项)
  5. "全部"选项绑定的value是空字符串""
  6. CodeToText是个大对象,属性是区域码,属性值是汉字 用法例如:CodeToText['110000']输出北京市
  7. TextToCode是个大对象,属性是汉字,属性值是区域码 用法例如:TextToCode['北京市'].code输出110000,TextToCode['北京市']['市辖区'].code输出110100,TextToCode['北京市']['市辖区']['朝阳区'].code输出110105

在element-china-area-data基础上新增两个配置:

1.setData是自定义数据来源。
参照格式:

 var REGION_DATA = [{ "value": "110000","label": "北京市", "children": [{ "value": "110100", "label": "市辖区",  "children": [{"value": "110101", "label": "东城区"}]}]}]

用法:

import {setData, getByArea, provinceAndCityData, regionData, provinceAndCityDataPlus, regionDataPlus, CodeToText, TextToCode } from 'region-tree-data'
setData(REGION_DATA)
console.log('regionData',regionData)
// regionData [{ "value": "110000","label": "北京市", "children": [{ "value": "110100", "label": "市辖区",  "children": [{"value": "110101", "label": "东城区"}]}]}]

// 说明: setData之后所有对象获取到的值包括getByArea都是setData自定义数据之后的值

2.getByArea是获取任意层级数的数据

/**
* area :number 需要获取的层级数,超过数据层级则获取所有的数据 
**/
getByArea(area)

用法:

import {setData, getByArea, provinceAndCityData, regionData, provinceAndCityDataPlus, regionDataPlus, CodeToText, TextToCode } from 'region-tree-data'
setData(REGION_DATA)
console.log('regionData',getByArea(1))
// regionData [{ "value": "110000","label": "北京市"}]
console.log('regionData',getByArea(2))
// regionData [{ "value": "110000","label": "北京市", "children": [{ "value": "110100", "label": "市辖区"}]}]

数据来源

我爬取的
国家统计局最新(2019)中国省市区县三级行政区划代码
(需要5级省市区县乡镇行政区划代码的童鞋同样可以从这里获取)