Tuesday, June 14, 2011

Re: django object into javascript variable

Each school is going to be a dictionay of school items that have the
respective City as the FK connection. You'll need to be more specific
with what you want when you start the loop through the school set as
this is a dictionay. If you have the __unicode__ definition set up in
your school model then it will spit out whatever field or combination
of fields you've set up as the value of the model.

Chances are each iterable object is a unicode object.

What are you seeing in the JS once the loop completes?

On Jun 14, 3:36 pm, "jay K." <jay.developer2...@gmail.com> wrote:
> Hello,
>
> I have the following code
>
> <script type="text/javascript">
> ...
> var city_schools = [{% for school in city.school_set.all %}"{{ school|
> escapejs }}"{% if not forloop.last %},{% endif %}{% endfor %}];
> ...
> </script>
>
> It is meant to store a number of schools in a particular city.
> Unfortunately I cannot figure out which format it is using to store
> the data, nor the type of variable it is being stored (array, list,
> string variable etc).
>
> What I intend to do is to use the variable "city_schools" as if it
> were a string array, and be able to traverse it using and index
> value...., I would be happy if it were stored as a string, then I
> could split it myself. The point is that so far I am unable to use the
> data stored inside city_schools
>
> Any suggestions would be greatly welcomed
>
> jay k.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate