固定选项(其他)始终位于下拉列表Angular中

问题描述 投票:0回答:1

我需要在下面提供的下拉列表中的最后一个选项。该列表目前按字母顺序排序。我正在使用管道对列表进行排序。

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;
      }
    });
  }
}
angular sorting pipe dropdown
1个回答
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;
   }
  });
 }

}

Document

© www.soinside.com 2019 - 2024. All rights reserved.