For cases like this one, it's better to use the more specialized  
methods Enumerable provides.

You can write this more concise by using "map" instead of the vanilla  
"each":

function tableToJSON(tableID) {
   return $$("#"+tableID+" tr").map(function(row){
     return row.descendants().pluck("innerHTML");
   }).toJSON();
}

Best,
Thomas

Am 14.06.2007 um 03:58 schrieb David Dashifen Kees:

>
> Not that I'm aware of without parsing the table element using the DOM
> walking functions.  Something like this might do it:
>
> function tableToJSON(tableID) {
>     var tableData = $A();
>     var rows = $$("#"+tableID+" tr).each(function(row) {
>        var cellData = $H(row.descendants().pluck("innerHTML"));
>        tableData.push(cellData);
>     });
>
>     return tableData.toJSON();
> }
>
> But I've not tried it, nor am I sure that will work.
>
>  - Dash -
> phil swenson wrote:
>> Is there a way to retrieve an HTML table in javascript and convert it
>> to JSON using prototype?
>>
>> I'm stumped :(
>>
>> phil
>>
>>
>>>
>>
>>
>
> >


--~--~---------~--~----~------------~-------~--~----~
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