How to sort an array of structs in ColdFusion

后端 未结 10 1775
余生分开走
余生分开走 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条回答
  •  旧时难觅i
    2020-12-17 10:21

    It's actually even easier with the new CF Closure support.

    Here's an example I worked on today where I wanted to sort an array of structs by a date stored in the struct. I was sorting in descending order.

    ArraySort(yourArrayOfStructs, function(a,b) {
        if ( DateCompare(a.struct_date, b.struct_date) == -1 ) {
            return true;
        } else {
            return false;
        }
    });
    

    I can't take total credit as I adapted this from Ray Camden's on Closures from 2012.

提交回复
热议问题