get disks() { const disks = this.unit.unitinfo.disks?.filter((disk) => disk.type ===…
- User
get disks() { const disks = this.unit.unitinfo.disks?.filter((disk) => disk.type === 'disk') ?? [] const boot = disks.find((d) => d.kname === this.boot) ?? '' if (!boot) { return [] } return [boot, ...disks] }
нужно добавть сортировку .sort((d1, d2) => d1.kname.localeCompare(d2.kname))
- Assistant
To incorporate sorting into your
disksgetter method, you can implement thesortmethod on the array of disks. Given your requirements, you'll sort the disks by theirknameproperty usinglocaleComparefor string comparison. Since you also have abootdisk that needs to appear first, you'll handle this logic by ensuring thebootdisk is not sorted along with the other disks. Here's how you can modify your code:get disks() { const disks = this.unit.unitinfo.disks?.filter((disk) => disk.type === 'disk') ?? []; const boot = disks.find((d) => d.kname === this.boot) ?? ''; if (!boot) { return []; } // Remove the boot disk from disks to sort the rest const sortedDisks = disks.filter((d) => d.kname !== this.boot).sort((d1, d2) => d1.kname.localeCompare(d2.kname)); // Return the boot disk followed by the sorted disks return [boot, ...sortedDisks]; }