Hi Yuval

Thank you so much for that and for coming back to me so quickly -
reworked the array as a multidimensional hash and it's now writing
JSON to the db beautifully. Should be able to make the monday deadline
now.

Thanks again

Damion

On Nov 27, 12:04 pm, yuval dagan <dag...@gmail.com> wrote:
> Hi
>
> I guess that the problem is in that
> array in js are not associative arrays even thought its looks like they can
> do that at first glance
>
> aAssetToggled['LNum0']['T'147'] = "true";
>
> the 'LNum0' and 'T147' are not realy indexes/keys of the array
>
> example:
>
> var a = new Array();
> a['x']=1;
> // a.length = 0 // check
> that why you get empty array -->> its realy empty
> because the x is not an index/key of the array but just another property of
> the object a.
>
> if you want a "keys array" use a hashhttp://api.prototypejs.org/language/Hash/
>
> its already has a toJSON method.
>
> I didnt check the prototype js toJSON  but I believe thats your problem
> regards
> Yuval
>
> On Sat, Nov 27, 2010 at 2:50 AM, theotherdy 
> <damion.yo...@googlemail.com>wrote:
>
> > I've been struggling for hours to get an array (aAssetToggled[LNum]
> > [T]) toJSON so I can save, by Ajax, it to a db in CakePHP - all I get
> > is '[]' - this is how Chrome shows it to me:
>
> > aAssetToggled: Array[0]
> > LNum0: Array[0]
> > T147: "true"
> > length: 0
> > __proto__: Array[0]
> > LNum1: Array[0]
> > LNum2: Array[0]
> > T147: "true"
> > length: 0
> > __proto__: Array[0]
> > LNum3: Array[0]
> > length: 0
> > __proto__: Array[0]
>
> > I'm sure I must be doing something wrong as all those 0's suggest that
> > Chrome, and presumably Prototype, think the array itself has no length
> > and contains zero-legth arrays. However, presumably because of the
> > lenience of the browsers, it still works exactly as it should in my js
> > code - I can ask aAssetToggled['LNum0']['T147'] for its value and I
> > get 'true'.
>
> > I define the array initially with
>
> > var aAssetToggled = new Array();
>
> > empty it occassionally with:
>
> > if (it needs to be emptied)
> >                {
> >                aAssetToggled = [];
> >                }
>
> > then repopulate it with:
>
> > if(!isArray(aAssetToggled['LNum0']))
> >                {
> >                aAssetToggled['LNum0'] = new Array();
> >                }
>
> > and:
>
> > aAssetToggled['LNum0']['T'147'] = "true";
>
> > Note that it was initially indexed with integers aAssetToggled[0][147]
> > but I thought that might have been the problem (lots of empty space?)
> > so went with string keys.
>
> > Any idea what I'm doing wrong?
>
> > Thank you
>
> > Damion
>
> > --
> > 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
> > prototype-scriptacul...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > prototype-scriptaculous+unsubscr...@googlegroups.com<prototype-scriptaculous%2bunsubscr...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/prototype-scriptaculous?hl=en.

-- 
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 prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to