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?

3
  • Can you clarify or rephrase the question? I'm not sure what you're asking here. Commented Oct 6, 2013 at 2:50
  • Please see if its understandable now Commented Oct 6, 2013 at 7:44
  • possible duplicate of Building HTML with templates versus building it in javascript? Commented Oct 6, 2013 at 8:02

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.