web名称索引自制

2024-01-17  本文已影响0人  小葵去旅行

需求:
将用户通过昵称首字母排序,可使用字母表进行索引


image.png
  abcList = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '#'],
abcList .forEach((val, index) =>{
  this.dataList.push({
    letter: val,
    list: [],
    index:index,
 })
})
for(let item of resultList) [//resultList 为接口请求得列的成员数组
  let first_letter = item.nickname.substr(0 ,1)
  this.datalist.find( val =>
    if(PinyimMalch.malch(first_letter, val.letter)){
        val.list.push(item);
        return val
    }else if(val.letter == '#'){
         val.list .push(item) ;
    }
   })
}

特殊字符”#”,可替换为其他值,显示的时候换回来即可

上一篇 下一篇

猜你喜欢

热点阅读