How to store data records for recurrent jQuery call

46 views
Skip to first unread message

Lio

unread,
May 18, 2013, 11:32:40 PM5/18/13
to web...@googlegroups.com
Hello there,

I have two DIV blocks on my page, one is a list of matched data records list (only a few fields each row) using <ol><li>, the other is detail record info when a record in above list is clicked. I want to use jQuery to update the content in the Block 2 whenever a record is clicked, without refreshing the whole page. 

Block 1
========================================
1. Record #1                                                            |
2. Record #2                                                            |
...                                                                           |
========================================

Block 2
========================================
field 1:                                                                      |
field 2:                                                                      |
.........                                                                      |
========================================

Here is the question:
A query was executed to create the list of records, and all records are already returned to View, How can I store all matched data records and pass the clicked one to jQuery functions? Otherwise I have to pass the record id to controller via ajax and execute another query and return it back to Block 2 every time a record row is clicked. This seems to be very inefficient. 

Any suggestion is appreciated.

Lio

Calvin

unread,
May 19, 2013, 9:50:33 PM5/19/13
to web...@googlegroups.com
I've not verified the code but something along the lines of:

<script>
   var rec = JSON.parse('{{=json.dumps(db(db.xyz.id>0).select().as_list())}}');
</script>

You could then write some javascript to populate block 2 using the rec object created...

Alan Etkin

unread,
May 21, 2013, 1:09:06 PM5/21/13
to web...@googlegroups.com
You could then write some javascript to populate block 2 using the rec object created...

I think this alternative should do what you want too:

(in a view)

{{=SCRIPT("""
var myRows = %(rows)s;
"""
% dict(rows=<set>.select().as_json()))}}


Then you can access the record values in myRows[n].fieldname from the jQuery event handlers.
 

冷春辉

unread,
May 23, 2013, 9:45:53 AM5/23/13
to web...@googlegroups.com
Thank you Calvin and Alan. I'm not familiar with JSON and not much content in the book at the moment. I will do my research based on your suggestions. 

Regards,
Lio



--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/9qu4EI8iOWY/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages