You're not seeing this work?  Looks like it works as you expect, at
least when looking at it with Firebug:

        testSortBy : function () {
                var RS =  [
                                        {id: 1, dateFrom: 20090101, dateTo: 
20090309, tariff: [
                                                {guest: 1, mon: 105, tue: 79, 
wed: 79, thu: 79, fri: 99, sat:
109, sun: 79},
                                                {guest: 2, mon: 89, tue: 89, 
wed: 89, thu: 89, fri: 109, sat:
119, sun: 89}
                                        ]},
                                        {id: 2, dateFrom: 20090302, dateTo: 
20090304, tariffhigh: 180,
tarifflow: 150, tariff: [
                                          {guest: 1, mon: 240, tue: 0, wed: 0, 
thu: 0, fri: 0, sat: 0,
sun: 0},
                                          {guest: 2, mon: 220, tue: 0, wed: 0, 
thu: 0, fri: 0, sat: 0,
sun: 0}
                                        ]},
                                        {id: 0, dateFrom: 20081216, dateTo: 
20081216, tariff: [
                                          {guest: 1, mon: 0, tue: 0, wed: 0, 
thu: 0, fri: 0, sat: 0, sun:
0}
                                        ]}
                ];

                console.log(RS);
                console.log(RS.sortBy(function(i){return i.dateFrom},this))
        }


The first console.log call shows me this:
0       Object id=1 dateFrom=20090101 dateTo=20090309 tariff=Object
1       Object id=2 dateFrom=20090302 dateTo=20090304
2       Object id=0 dateFrom=20081216 dateTo=20081216 tariff=Object


The second shows me this:
0       Object id=0 dateFrom=20081216 dateTo=20081216 tariff=Object
1       Object id=1 dateFrom=20090101 dateTo=20090309 tariff=Object
2       Object id=2 dateFrom=20090302 dateTo=20090304

Is that not what you're expecting to see?


On Dec 18, 8:08 am, George <[email protected]> wrote:
> Just wondering if anyone had any ideas about how to sort JSON data.
> I'm sure there must be an easy way.
>
> Many thanks
>
> George
>
> On Dec 16, 12:43 pm, George <[email protected]> wrote:
>
> > Hi Folks,
> > I wondered if there was a way to sort a JSON array.  Here's an
> > example:
>
> > var RS =  [
> > {id: 1, dateFrom: 20090101, dateTo: 20090309, tariff: [
> >   {guest: 1, mon: 105, tue: 79, wed: 79, thu: 79, fri: 99, sat: 109,
> > sun: 79},
> >   {guest: 2, mon: 89, tue: 89, wed: 89, thu: 89, fri: 109, sat: 119,
> > sun: 89}
> > ]},
> > {id: 2, dateFrom: 20090302, dateTo: 20090304, tariffhigh: 180,
> > tarifflow: 150, tariff: [
> >   {guest: 1, mon: 240, tue: 0, wed: 0, thu: 0, fri: 0, sat: 0, sun:
> > 0},
> >   {guest: 2, mon: 220, tue: 0, wed: 0, thu: 0, fri: 0, sat: 0, sun: 0}
> > ]},
> > {id: 0, dateFrom: 20081216, dateTo: 20081216, tariff: [
> >   {guest: 1, mon: 0, tue: 0, wed: 0, thu: 0, fri: 0, sat: 0, sun: 0}
> > ]}
> > ]
>
> > RS.sortBy(function(i){return i.dateFrom},this)
>
> > I've simplified this code slightly but you should get the general
> > idea.
>
> > I'm trying to reorder by dateFrom but I can't get sortBy to sort in
> > this case.  Anyone know what I'm doing wrong, or is there an
> > altogether better way?
>
> > Many thanks
>
> > George
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to