美文网首页
根据不同类型判断进行数据排序

根据不同类型判断进行数据排序

作者: 高磊_IT | 来源:发表于2020-11-25 15:59 被阅读0次

Json数据

    private data: any[] = [
      {
        accountType: "R",
        accountTypeDesc: "房间账1",
      },
      {
        accountType: "N",
        accountTypeDesc: "虚拟账2",
      },
      {
        accountType: "R",
        accountTypeDesc: "房间账2",
      },
      {
        accountType: "X",
        accountTypeDesc: "现付账1",
      },
      {
        accountType: "X",
        accountTypeDesc: "现付账2",
      },
      {
        accountType: "N",
        accountTypeDesc: "虚拟账1",
      }
    ];
// 根据不同字段排序
    this.data.sort(function (a, b) {
      var x = "accountType"; //要排序字段
      if (a[x] < b[x]) {
        return -1;
      }
      if (a[x] > b[x]) {
        return 1;
      }
      return 0;
    });
    // console.log(this.data);
  }

相关文章

网友评论

      本文标题:根据不同类型判断进行数据排序

      本文链接:https://www.haomeiwen.com/subject/lxyniktx.html