try this
In a view default/list.html
{{response.headers['Content-Type']='application/json'}}
{{=rooms.json()}}
Mind that list is not a good name for a function because it is a built-
in python function.
On Feb 22, 9:08 am, Ed Greenberg <[email protected]> wrote:
> In my 'room' controller, I did this:
> def list():
> rooms =
> db((db.rooms.customer==session.customer_id)&(db.rooms.property==db.properti
> es.id)).select(db.rooms.ALL,
> db.properties.ALL, orderby=db.properties.short_desc)
> return dict(rooms=rooms)
>
> which I thought was way cool.
>
> In my 'room/list.html' view, I'm able to do this:
>
> {{for room in rooms:}}
> <p>
> <a href="{{=URL(f='show',
> args=room.rooms.id)}}">{{=room.properties.short_desc}}:
> {{=room.rooms.short_desc}}</a>
> <a href="{{=URL(f='update', args=room.rooms.id)}}">[edit]</a></
> p>
> {{pass}}
>
> Which I also thought was way cool.
>
> Then I tried to pass it to generic.json. I called rooms/list.json, and
> got got 'no json'. After commenting out the try/catch block, I found
> this:
> Traceback (most recent call last):
> File "/var/www/vhosts/web2py.hens-teeth.net/httpdocs/web2py/gluon/
> restricted.py", line 188, in restricted
> exec ccode in environment
> File "/var/www/vhosts/web2py.hens-teeth.net/httpdocs/web2py/
> applications/InsuranceInventory/views/generic.json", line 5, in
> <module>
> #try:
> AttributeError: 'dict' object has no attribute 'id'
>
> Dumping the row object out, I discover that this is accurate. There is
> no attribute 'id'. All the attribute names are based on the two
> tables. For instance, 'rooms.id', 'property.id', etc.
>
> I made my own list.json file, and attempted to work with the returned
> rows object, but I got stuck since I don't know how to access an
> attribute of an object, when the attribute has a dot in it.
>
> Anybody been here? How do I work with this object. I need the json
> output in order to populate a rooms dropdown using jQuery.
>
> Thanks.