💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[TOC] #### 类通讯录数据结构处理 1. 服务端数据结构 ![](https://box.kancloud.cn/3bcdd7c2a38eff11085816ecb4de53e5_623x687.png) 2. 处理排序,得到一维数组 ~~~ _normalizeSinger(list) { let map = { hot: { title: HOT_NAME, items: [] } } list.forEach((item, index) => { // 取前10条作为热门数据 if (index < HOT_SINGER_LEN) { map.hot.items.push(new Singer({ name: item.Fsinger_name, id: item.Fsinger_mid })) } const key = item.Findex if (!map[key]) { map[key] = { title: key, items: [] } } map[key].items.push(new Singer({ name: item.Fsinger_name, id: item.Fsinger_mid })) }) // 为了得到有序列表,我们需要处理 map let ret = [] let hot = [] for (let key in map) { let val = map[key] if (val.title.match(/[a-zA-Z]/)) { ret.push(val) } else if (val.title === HOT_NAME) { hot.push(val) } } ret.sort((a, b) => { return a.title.charCodeAt(0) - b.title.charCodeAt(0) }) return hot.concat(ret) } ~~~