合同小程序前端代码仓库
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.

19 lines
478 B

3 months ago
  1. export default function transformBrands(inputData) {
  2. const groups = {};
  3. // 遍历输入数据,按首字母分组
  4. inputData.forEach(brand => {
  5. const letter = brand.bfirstletter;
  6. if (!groups[letter]) {
  7. groups[letter] = [];
  8. }
  9. groups[letter].push({ name: brand.name,id:brand.id });
  10. });
  11. // 将分组转换为数组并按字母排序
  12. return Object.keys(groups)
  13. .sort()
  14. .map(letter => ({
  15. letter,
  16. cars: groups[letter]
  17. }));
  18. }