我需要在下面提供的下拉列表中的最后一个选项。该列表目前按字母顺序排序。我正在使用管道对列表进行排序。
export class SortDropdownPipe implements PipeTransform {
transform(input: any, description: string) {
if (!input) return [];
return input.sort(function (itemA, itemB) {
if (itemA[description] > itemB[description]) {
return 1;
} else if (itemA[description] < itemB[description]) {
return -1;
} else {
return 0;
}
});
}
}
以下代码应该可行
export class SortDropdownPipe implements PipeTransform {
transform(input: any, description: string) {
if (!input) return [];
return input.sort(function(itemA, itemB) {
if (itemA[description] - itemB[description]) {
return 1;
} else if (itemA[description] - itemB[description]) {
return -1;
} else {
return 0;
}
});
}
}