Sounds like you're looking for response.json def test(): coords = ((1,2), (3,4), (5,6)) return response.json(coords=coords)
Returns a javascript array formatted like: [[1, 2], [3, 4], [5, 6]] Or you can use response.json(dict(coords=coords)) to get a javascript object: {"coords": [[1, 2], [3, 4], [5, 6]]} Note that you also don't have to immediately return the result of response.json, you can save it and output it in the view, inside a <script> tag, for example -----Original Message----- From: web2py@googlegroups.com [mailto:web...@googlegroups.com] On Behalf Of 1904 Sent: Thursday, December 02, 2010 9:12 AM To: web2py-users Subject: [web2py] convert python list to javascript array Hello, i m totally new to web2py and im trying to use it with google maps api and javascript to build a map. So I got some longtiudes and latidues from a MySQL database. The problem is that I cant convert the Python list [with the lat and lng values] from the database into a javascript array which is needed. I build the list with the values in a controller file and return it to the view file. Python list: coordinates((1,2) , (3,4) , (5,6)) I tried it on this way: while(j<=len()) //len = length of coordinates { var coor[{{=x}}][0] = {{=coordinates[y][0]}}; var coor[{{=x}}][1] = {{=coordinates[y][1]}}; j++; } but it is not possible because Y doesnt raise... So the question is how can I use JS variables and/or Python variables together? Thanks for help This communication, including any attachments, does not necessarily represent official policy of Seccuris Inc. Please see http://www.seccuris.com/Contact-PrivacyPolicy.htm for further details about Seccuris Inc.'s Privacy Policy. If you have received this communication in error, please notify Seccuris Inc. at i...@seccuris.com or at 1-866-644-8442.