jquery - Retrieve dictionary value jinja -


i have python dictionary looks this

[{"hat": 91, "d1b": 2, "d1c": 1, "d1d": 5, "d1e": 7, "d1f": 77, "d1e": 999} {"hat": 1, "d2b": 2, "d2c": 3, "d2d": 4, "d2e": 5, "d2f": 6, "d2e": 7} {"hat": 1, "d3b": 2, "d3c": 3, "d3d": 4, "d3e": 5, "d3f": 6, "d3e": 7}] 

and pass dictionary object (mydict) python jinja

what i'm tryrng loop through each dictionary , print out value of key search for. , have show in jquery alert box.

$(document).ready(function() {          {% in mydict %}           {{ loop.index0 }}, {{a,["hat"] }}                alert( {{ hat }} );             {% endfor %}         }); 

when go web page gives me error of

uncaught syntaxerror: unexpected token &  $(document).ready(function() {             0, (undefined, [[hat[])                alert(  );            1, (undefined, [hat])                alert(  );            2, (undefined, [hat])                alert(  );          }); 

its not being defined, , not printing alert.

you need use call python dictionary (it's not collection):

{% in dict %}     {{ i['hat'] }} {% endfor %} 

collections can accessed dictionaries, , dictionaries cannot called collection. way need use i.hat if collection or i['hats'] if it's collection or dictionary.

just try replace it:

alert( {{ hat }} ); 

to:

alert( {{ i['hat'] }} ); 

Comments