pys () {
// ['A', 'B']
return this.cityList.map(item => item.py)
},
筛选数组对象中的一个属性作为数组返回新数组
hotCityList () {
return this.cities.filter(item => item.isHot)
},
为true才返回
cityList () {
let result = []
this.cities.forEach(item => {
let py = item.pinyin.charAt(0).toUpperCase()
let index = result.
(city => city.py === py)
if (index > -1) {
result[index].list.push(item)
} else {
let obj = {
py,
list: [item]
}
result.push(obj)
}
})
return result.sort((a, b) => a.py.charCodeAt() - b.py.charCodeAt())
},
对数组进行调整
网友评论