api_bank_list(listParams).then(result => {
if (result && result.list.length > 0) {
let hotList = [];
let sectionList = [];
//先按照字母排序
result.list.sort((a, b) => {
let aFirstLetter = a.name.toLocaleUpperCase().substring(0, 1);
let bFirstLetter = b.name.toLocaleUpperCase().substring(0, 1);
return aFirstLetter.localeCompare(bFirstLetter);
})
let name = result.list[0].name.toLocaleUpperCase();
let obj = {
title: name.substring(0, 1),
data: []
}
result.list.map((item, index) => {
let firstLetter = item.name.toLocaleUpperCase().substring(0, 1);
if (obj.title == firstLetter) {
obj.data.push(item)
} else {
sectionList.push(obj);
obj = {
title: firstLetter,
data: [item]
}
}
//sort>0,就是火爆 (如果是搜索就不需要筛选)
if (!isSearch && item.sort > 0) {
hotList.push(item);
}
})
this.setState({
sectionList,
hotList
})
}
}).catch(error => {
});
网友评论