sorry.. im not trying to be cryptic. Maybe this screenshot of my debugger will help. Im pretty sure if you can visualize from the debugger image you will be able to easily tell me how to do it.
Should have mentioned that you could also implement the sort function outside of the call to sort:
Code:
function bySPD( o1, o2 )
{
if ( o1.sPD == o2.sPD ) return 0; // optional...not needed if values will never be equal
return ( o1.sPD < o2.sPD ) ? -1 : 1;
}
and then just do:
ar.sort( bySPD );
That's not perfect: You really should return zero if o1.sPD == o2.sPD, but if that isn't too important to you, the above would work.
If you really wanted to be able to do
Code:
ar.sortBySPD();
or
ar.sortBy("sPD");
then you could add that as a method on a custom array prototype, implemented using the code I showed.
Thanks for your help. This worked perfectly. I appreciate all the other options you provided as well.
Now I have some more crazy things I gotta work through. For instance some of these objects within the array can not be sorted if they are a parent of other objects.
bChildren = 'true' would indicate that the item is a parent and should not be part of the sort.
Its a BOM (Bill of Materials) that Im trying to compose based on this array.
Do you think it would be best if I composed/sorted the array at the c# level before I pass the array down to the client?
Last edited by salazar44; 06-20-2011 at 06:34 PM..
[QUOTE=salazar44;1103601]
Now I have some more crazy things I gotta work through. For instance some of these objects within the array can not be sorted if they are a parent of other objects.
bChildren = 'true' would indicate that the item is a parent and should not be part of the sort.
Its a BOM (Bill of Materials) that Im trying to compose based on this array.
[/quote[
If they are children, then they should not be members of the array of parent objects.
Each parent should have a reference to its own array of children.
Quote:
Do you think it would be best if I composed/sorted the array at the c# level before I pass the array down to the client?
Absolutely! In fact, if this info is coming from a database, then the sorting should almost surely be done in SQL, even before C# gets involved.
This also applies to the consolidation question you posted in your other thread. It would be *TRIVIAL* to do that consolidation in SQL. And that almost surely should be done there, not in C# and not in JavaScript.