How to sort an array of structs in ColdFusion

后端 未结 10 1755
余生分开走
余生分开走 2020-12-17 10:00

I have an array of structs in ColdFusion. I\'d like to sort this array based on one of the attributes in the structs. How can I achieve this? I\'ve found the StructSort fun

10条回答
  •  眼角桃花
    2020-12-17 10:33

    Here is something that closely resembles the original StructSort(). It also supports the pathToSubElement argument.

    
      
      
      
      
    
      
      
      
      
    
      
        
      
    
      
    
      
        
      
    
      
    
    

    Usage / test:

     
      arr = ArrayNew(1);
    
      for (i = 1; i lte 5; i = i + 1) {
        s = StructNew();
        s.a.b = 6 - i;
        ArrayAppend(arr, s);
      }
     
    
    
    
    

    Result:

    ArrayOfStructSort Result

提交回复
热议问题