0

Below is a snippet of my django template where I am programmatically creating forms and dropping them into a table based on a list of assets on the backend.

I want to move this functionality over to jquery/js. Rather than looping through a list of assets in django, the assets will exist as a js array. I assume this is straight forward I'm just having a hard time inserting the js vars into the html

<table class="table">
{% for asset in assets %}
<form id="{{ asset }}-edit-form" action="{% url 'asset-update' %}" method="POST">
      {% csrf_token %}
    <tr>
      <td>{{ forloop.counter }}</th>
      <td><img height="45" src="{{ asset.file }}"></td>
      <td>
        <i class="glyphicon glyphicon-pencil" />
      <input type="text" id="id_{{ asset }}" class="description" value="{{ asset.description }}">
      </td>
      <td>

        <br>
        <select name="tags" id="{{ asset }}-tags" class="{{ asset }}">
          {% for tag in asset.tags.names %}
            <option selected="{{ tag }}">{{ tag }}</option>
          {% endfor %}
          {% for asset_tag in asset_tags %}
            <option value="{{ asset_tag}}">{{ asset_tag }}</option>
          {% endfor %}
        </select>
      </td>
      <td><center>
        <button class="btn btn-primary" name="asset" value="{{ asset }}">{% trans "Save" %}</button>
      </center>
        </td>
    </tr>
    </form>
  {% endfor %}
  </table

given that I have a js array of assets with all of the properties needed (ie. file, description, tags)

How can I create a table like above via jquery/js? The main issue I keep running into is how to insert html into the table using js vars.

js array=
{ "asset": "{{ asset}}", "description": "{{ asset.description }}", "tags": "some tags" }

0 Answers0