Re: Accessing list of dictionaries in jQuery

2013-04-09 Thread Larry Martell
Thanks! This works perfectly. On Mon, Apr 8, 2013 at 6:01 PM, Nikolas Stevenson-Molnar wrote: > Injecting data into a template can be tricky. I would recommend doing > two things: > > 1) Serialize your data to JSON in your view first using Python's json > module. Something like this: images_

Re: Accessing list of dictionaries in jQuery

2013-04-09 Thread Larry Martell
On Tue, Apr 9, 2013 at 2:45 AM, Tom Evans wrote: > On Tue, Apr 9, 2013 at 1:24 AM, Larry Martell wrote: >> I appreciate the suggestion, but using a hidden field sounds very >> kludgy. Is there no other way? >> > > Remember that JSON = JavaScript Object Notation - its a way of writing > literal JS

Re: Accessing list of dictionaries in jQuery

2013-04-09 Thread Tom Evans
On Tue, Apr 9, 2013 at 1:24 AM, Larry Martell wrote: > I appreciate the suggestion, but using a hidden field sounds very > kludgy. Is there no other way? > Remember that JSON = JavaScript Object Notation - its a way of writing literal JS objects. var data = {{ json_encoded_literal }}; You've

Re: Accessing list of dictionaries in jQuery

2013-04-08 Thread Nikolas Stevenson-Molnar
Injecting data into client code is bound the be kludgy any way you slice it. The reason for passing it through a hidden element has to do with correct escaping of characters. Consider the following: $.parseJSON("{{ images_as_json }}"); and lets say this is rendered as: $.parseJSON("{foo: "bar"}"

Re: Accessing list of dictionaries in jQuery

2013-04-08 Thread Larry Martell
I appreciate the suggestion, but using a hidden field sounds very kludgy. Is there no other way? On Mon, Apr 8, 2013 at 6:01 PM, Nikolas Stevenson-Molnar wrote: > Injecting data into a template can be tricky. I would recommend doing > two things: > > 1) Serialize your data to JSON in your view fi

Re: Accessing list of dictionaries in jQuery

2013-04-08 Thread Nikolas Stevenson-Molnar
Injecting data into a template can be tricky. I would recommend doing two things: 1) Serialize your data to JSON in your view first using Python's json module. Something like this: >>> images_as_json = json.dumps(images) 2) Rather than trying to inject it directly into JavaScript, which can cause

Accessing list of dictionaries in jQuery

2013-04-08 Thread Larry Martell
I am passing a list of dictionaries to my template. In the template language I can do this and it works as expected: {% for row in images %} {% endfor %} But I need to process this data in jQuery. If I pass images into a function like this: my_func({{ images