I'd probably put the script tag outside the for loop.

But I don't see where you're passing should_have_found_list to the
context.  If it's an item (top level) in form.field_mapping, then it needs
to be something like:

  ...
  {% for shbr in form.field_mapping.should_have_found_list %}
  ...


I don't understand why you are JSON encoding form.field_mapping for the
fields template variable.  There could be perfectly valid reasons.  But if
that was supposed to make should_have_found_list available in JavaScript,
it could work, but you would have to do something with the fields variable
inside a script tag, such as use it in a var statement to initialize a
variable (var fields = {{ fields }};), and then dereference it in JS.


On Tue, Oct 15, 2013 at 11:45 AM, Larry Martell <larry.mart...@gmail.com>wrote:

> On Tue, Oct 15, 2013 at 6:46 AM, drakko <gundar...@gmail.com> wrote:
>
>> Hello!
>>
>> I'm new to Django and Javascript and so I need some help with passing
>> list from django template to Javascript.
>>
>> The list is available in template (template.html) by using
>>
>> {% for shbf in should_have_found_list %}
>>
>>
>> but I have no idea how to access this list from Javascript.
>>
>> The should_have_found_list is created in context.py file like:
>>
>> should_have_found_list = ShouldHaveFound.objects.filter(enabled=1)
>>
>>
>> and passed to template in view.py as a part of dictionary:
>>
>> return render_to_response(template_name, RequestContext(request, {
>>>
>>>         'form': form,
>>>
>>>         'fields': simplejson.dumps(form.field_mapping),
>>>
>>>     }))
>>>
>>>
>> I would appreciate some guidance :)
>>
>
> You can embed js anywhere in your template, e.g.:
>
> {% for shbf in should_have_found_list %}
>     <script type="text/javascript">
>         my_js_function(shbf);
>     </script>
> {% endfor %}
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACwCsY4PvmRLOkpCrsRps4xLixqRbjkeMhqdvoOuS%2B3g9-RgEA%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB%2BAj0uPASMP%3D6Sau5A3DpG8ve0389qtq%3Dn0KOdo8yDfSULsWQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to