对获得的数据(数组)进行分类处理

有相同属性的对象放在同一个数组:

_nomarSinger (list) {  //传入一个list数组,对数组中的数据进行封装
      let map = {
        hot: {  //热门
          title: HOT_NAME,
          items: []
        }
      };
      console.log(list);

      list.forEach((item, index) => {
        if(index < HOT_NAME_LEN){
          map.hot.items.push(new Singer(
            item.Fsinger_id,
            item.Fsinger_name,
            item.Fsinger_mid
          ));
        }
        const key = item.Findex;
        if(!map[key]){  // 按key来进行分类
          map[key] = {
            title: key,
            items: []
          }
        }
        map[key].items.push(new Singer(
            item.Fsinger_id,
            item.Fsinger_name,
            item.Fsinger_mid
          ));
      });
      console.log(map);
    }

封装Singer类:

export default class Singer {
    constructor(id, name, mid) {
        this.id = id;
        this.name = name;
        this.avator = `https://y.gtimg.cn/music/photo_new/T001R300x300M000${mid}.jpg?max_age=2592000`
    }
}

最后得到的结果:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值