使用区划代码的省市县三级联动下拉框
从网上又找了一份截止2009年底的全国行政区划代码表,重写了省市县三级联动下拉框。如下:
test.html
Area.js
格式转换工具:public class Test2 {public static void main(String[] args) throws Exception {Workbook workbook = Workbook.getWorkbook(Test2.class.getResourceAsStream("行政区划代码(截至2009年12月31日).xls"));Sheet sheet = workbook.getSheet(0);/** key=code, value=area, area is string or map */Map<String, Object> roots = new HashMap();/** key=name, value=children map */Map<String, Map> lastProvince = null;/** key=name, value=children map */Map<String, Map> lastCity = null;for (int i = 3; i < sheet.getRows(); i++) {String code = trimToNull(sheet.getCell(0, i).getContents());String name = trimToNull(sheet.getCell(1, i).getContents());if (code == null && name == null) continue;if (isProvince(code)) {lastProvince = new HashMap();lastProvince.put(name, new HashMap());roots.put(code, lastProvince);continue;}if (isCity(code)) {lastCity = new HashMap();lastCity.put(name, new HashMap());lastProvince.values().iterator().next().put(code, lastCity);continue;}lastCity.values().iterator().next().put(code, name);}workbook.close();ObjectMapper mapper = new ObjectMapper();mapper.writeValue(new File("area2.json"), roots);}static String trimToNull(String text) {if (text == null) return null;text = text.replaceAll("\\s| |\u00a0", "");return text.length() == 0 ? null : text;}static boolean isProvince(String code) {return code.endsWith("0000");}static boolean isCity(String code) {return !isProvince(code) && code.endsWith("00");}}