Hey guys,
Thanks for the great responses!

The other day I ended up creating my associative array on the server side so
that it instead of an array of objects, it output a JSON string that was of
the format :
'{ { "VidID":1, "VidPathStr":"somepath", "VidDescrip":"somedescription" }, {
"VidID":2, "VidPathStr":"Ima path", "VidDescrip":"blah blah" } , ...} '

...this was different than what I had before which was indeed '[ { hash1...
}, { hash2... } ...]'

This way I was able to access the hashes as in the for loop below:

        function SearchVidSid2(SID) {
          var pars = 'FORM.Sid=' + parseInt(SID);
          var url = "/ss/Model/AjaxCalls/caller_getVidsBySid2.cfm"

          new Ajax.Request(url,
            {
                method: 'post',
                parameters: pars,
                onComplete: function(transport)  //get from JSON string
                  {
                    var jsonarray = transport.responseText.evalJSON(true);

                    for (var i=0; i < Object.keys(jsonarray.VidID).size();
i++) {
                        // for simplicity's sake in demonstrating how I
accessed the values in the hashes, showing alerts for each iteration
                        alert(Object.values(jsonarray.VidID)[i]);
                        alert(Object.values(jsonarray.VidPathStr)[i]);
                        alert( Object.values(jsonarray.VidDescrip)[i]);

                    }
                  ....

How does that look?
(btw, in response to your message, in Seattle it's 3:03 a.m.... time to go
to bed (finally)! :)  ...would like to hear your thoughts though!
cheers,
Mark

On 6/9/07, Christophe Porteneuve <[EMAIL PROTECTED] > wrote:
>
>
> Hey Gareth, howzit? :-)
>
> Gareth Evans a écrit :
> > Could someone else identify the best way to get an array of hashes
> > (which is returned as a string from an ajax call) and then get something
> > you can iterate?
>
> So if I get you right, you're saying that the following responseText
> (just abbreviating with '...' in there):
>
> '[ { hash1... }, { hash2... } ...]'
>
> won't get eval'd properly when you do xhr.responseText.evalJSON
> ().  Correct?
>
> What if you tried to wrap it in an extra object with a single property,
> something like:
>
> '{ data: [ { hash1... }, { hash2... } ...] }'
>
> And then you'd access the data property of the eval'd object?  Would
> that work for you?  I'm sorry I don't have time to test this just now,
> but I thought I'd suggest a possible lead.
>
> 'HTH
>
> --
> Christophe Porteneuve aka TDD
> [EMAIL PROTECTED]
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" 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/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to