0

This must be pretty basic or Im just thinking it wrong. Please help.

In a template I query a few objects and display them as follows:

{% for obj in objects %}
 {{obj.attr1}}
 {{obj.attr2}}
{% endfor }}

Now, suppose I create another object at the server side and respond back the new object data with AJAX, for example this is the response: :

{'attr1':some_attribute,
 'attr2':some_attribute'}

How do i append the new object to the for loop of objects?

H H H
  • 489
  • 1
  • 7
  • 20
  • Can you clarify or rephrase the question? I'm not sure what you're asking here. – Joseph Oct 06 '13 at 02:50
  • Please see if its understandable now – H H H Oct 06 '13 at 07:44
  • possible duplicate of [Building HTML with templates versus building it in javascript?](http://stackoverflow.com/questions/4240026/building-html-with-templates-versus-building-it-in-javascript) – zinking Oct 06 '13 at 08:02

1 Answers1

1

You need to add some html tags to your content like this:

<ul class="content">
{% for obj in objects %}
    <li>{{obj.attr1}}, {{obj.attr2}}</li>
{% endfor %}
</ul>

then use jQuery to append new object:

$('.content').append('<li>' + data.attr1 + ', '+ data.attr2 + '</li>');

data is the response object.

mariodev
  • 13,928
  • 3
  • 49
  • 61