合同小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

20 lines
478 B

export default function transformBrands(inputData) {
const groups = {};
// 遍历输入数据,按首字母分组
inputData.forEach(brand => {
const letter = brand.bfirstletter;
if (!groups[letter]) {
groups[letter] = [];
}
groups[letter].push({ name: brand.name,id:brand.id });
});
// 将分组转换为数组并按字母排序
return Object.keys(groups)
.sort()
.map(letter => ({
letter,
cars: groups[letter]
}));
}