美文网首页
数据处理筛选

数据处理筛选

作者: 未来在奋斗 | 来源:发表于2020-02-23 21:01 被阅读0次
    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())
    },
    对数组进行调整

    相关文章

      网友评论

          本文标题:数据处理筛选

          本文链接:https://www.haomeiwen.com/subject/uaewqhtx.html