代码之家  ›  专栏  ›  技术社区  ›  SmartestVEGA

SORTBY LINQ不工作

  •  -2
  • SmartestVEGA  · 技术社区  · 7 年前

    我正在尝试使用LINQ对API的结果进行排序,但它不起作用。

    我期望网格中基于主机名的已排序行,但我得到的是未排序行。

    this.addservers=res.sortby(x=>x.hostname);

     getAddServer() {
            this.AddServerService.getAddServer()
                .subscribe(res => {
                    this.addservers = res.sortBy(x=> x.hostname);               
    
                    this.total = this.addservers.length;
                });
    
        }
    

    我在这里做错什么了?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Nascent    7 年前
    I think following should work.
    
    this.addservers = res.sort(
    function (x, y) {
        return  x.hostname > y.hostname? 1 : 0;
    }
    );