//数据格式化的方法
const formatCityData = (list) => {
const cityList = {}
const cityIndex = []
/**
- 1 遍历list数组
- 2 获取每一个城市的首字母
- 3 判断cityList中是否有该分类
- 4 如果有,直接往该分类中push数据
- 5 如果没有,就先创建一个数组,然后,把城市信息添加到数组中
- /
list.forEach(item => {
const first = item.short.substr(0, 1)
** // 这是什么写法cityList[first]?**
if (cityList[first]) {
cityList[first].push(item)
} else {
cityList[first] = [item]
}
});
return {
cityList,
cityIndex
}
}