Parameter
Converts any struct to a sorted struct.
If the input struct has an inner struct, StructToSorted does not sort the inner struct. StructToSorted only sorts structs at the first level.
A structure.
ColdFusion (2018 release): Introduced named parameters.
ColdFusion (2016 release) Update 3: Added the function.
StructToSorted(struct, sorttype, sortorder, localeSensitive)
<!--- Syntax with callback function---> StructToSorted(struct,callback)
|
Parameter |
Description |
|---|---|
|
struct |
The structure to be sorted. |
|
sortType |
Sort types are text or numeric. Text value produces a case-insensitive sort. |
|
sortOrder |
Ascending (" asc ") or descending ("desc"). |
|
localeSensitive |
True or false. |
|
callback |
The callback function to be used. The function compares the values in a struct and returns -1,0, and 1 depending on the values. |
<cfscript> mystruct=StructNew(); mystruct.k1="one"; mystruct.k4="five"; mystruct.k2="three"; mystruct.k3="two"; mystr=StructToSorted(mystruct,"text","asc",false); writedump(mystr); </cfscript>
<cfscript>
mystruct=StructNew();
mystruct.k1="one";
mystruct.k4="five";
mystruct.k2="three";
mystruct.k3="two";
callback=function(value1,value2,key1,key2)
{
if (key1>key2)
return 1;
else
return -1;
};
mystr=StructToSorted(mystruct,callback);
writedump(mystr);
</cfscript>
<cfscript>
mystruct=StructNew();
mystruct.k1="one";
mystruct.k4="five";
mystruct.k2="three";
mystruct.k3="two";
mystr=mystruct.ToSorted("text","asc",false);
writedump(mystr);
</cfscript>
<cfscript>
mystruct=StructNew();
mystruct.k1="one";
mystruct.k4="five";
mystruct.k2="three";
mystruct.k3="two";
callback=function(value1,value2,key1,key2)
{
if (key1>key2)
return 1;
else
return -1;
};
mystr=mystruct.ToSorted(callback);
writedump(mystr);
</cfscript>
Sign in to your account