我希望读取这段代码中city2的长度而不是city2children的长度该怎么办function useCascaderAreaData const city_list city county_list county province_list province = areaList; const provinceMap = __PURE__ new Map;
要读取city2的长度而不是city2.children的长度,你可以使用city2.children.length来获取city2的长度。修改代码如下:
Object.keys(county).forEach((code) => {
const city2 = cityMap.get(code.slice(0, 4));
if (city2 && city2.children.length == 1) {
city2.children.push(makeOption(county[code], code));
}
});
在这个修改后的代码中,我们首先检查city2是否存在,然后再使用city2.children.length获取city2的长度。
原文地址: http://www.cveoy.top/t/topic/h3Ba 著作权归作者所有。请勿转载和采集!