字典排序

    dict = {'a':21, 'b':5, 'c':3, 'd':54, 'e':74, 'f':0}
    new_dict = sorted(dict.iteritems(), key=lambda d:d[1], reverse =True)
    print new_dict

 

列表排序

    [{'businessname': '暂无', 'requestCount': 264, 'maxtime': '76.00', 'avgtime': '8.81', 'appname': 'wszx-svc', 'errRequest': 0, 'mintime': '4.00', 'interface':  'gov.etax.dzswj.xxzx.channel.IChannelAgent'}]

    ilist = sorted(ilist,key=lambda e:float(e.__getitem__('avgtime')))
    ilist = sorted(ilist,key=lambda e:float(e.__getitem__('avgtime')),reverse=True)

   多级排序,先按照score,再按照no排序
   new_s_2 = sorted(new_s,key = lambda e:(e.__getitem__('score'),e.__getitem__('no')))

实例代码

     handleSortChange1(sortobj)
      {
         this.sortColumn=sortobj.prop;
         let sortType=sortobj.order;
         if(sortType=="ascending")
         {
            this.sortType="asc";
         }
         else
         {
           this.sortType="desc";
         }
         this.currentPage = 1;
         this.getinferfaceCall();
      },
     getinferfaceCall()
     {
      this.tbflag=true;
      return this.$http.getInterfaceCall(
          {
            "pageIndex":this.currentPage,
            "pageSize":this.pageSize,
            "startTime":this.startTtime,
            "endTime":this.endTime,
            "sortColumn":this.sortColumn,
            "sortType":this.sortType
           },{notify:true})
         .then((data) => 
          {
            this.interfaceList=data.list;
            this.total=data.total;
          }).finally(() =>{
            this.tbflag=false;
          });
     }
前端

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-11
猜你喜欢
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案