How to sort an array of structs in ColdFusion

后端 未结 10 1754
余生分开走
余生分开走 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:15

    I don't have the reputation points to comment on @mikest34 post above but @russ was correct that this callback no longer works the way it was explained.

    It was Adam Cameron who discovered that when using arraySort with a callback, it no longer requires a True/False response but rather:

    -1, if first parameter is "smaller" than second parameter
    0, if first parameter is equal to second parameter
    1, first parameter is "bigger" than second parameter

    So the correct callback is:

    ArraySort(yourArrayOfStructs, function(a,b) {
        return compare(a.struct_date, b.struct_date);
    });
    

    Testing and working in CF2016

提交回复
热议问题