0
나는 사용자가 편집 할 수있는 동적으로 채워진 html 테이블을 가지고 있습니다. 행을 추가하면 행을 삭제할 수 있습니다.이 테이블은 자바 스크립트를 통해 관리됩니다. 문제는 테이블이 양식 안에있을 때에도 서버가 게시물 데이터를 가져 오지 않는다는 것입니다. 여기 템플릿 코드입니다 :양식 내에서 html 테이블의 게시물 데이터 가져 오기? Django
{% extends 'base.html' %}
{% block content %}
<script>
function add_row(){
var table = document.getElementById("body");
var row = table.insertRow(table.rows + 1);
var cell = row.insertCell(0);
var combo1 = document.createElement("select");
var option;
{% for opt in options_all %}
option = document.createElement("option");
option.setAttribute("value", "{{ opt.id }}");
option.text="{{ opt.description }}";
combo1.add(opcion);
{% endfor %}
cell.appendChild(combo1);
}
</script>
<form action='.' method='post'>
{% csrf_token %}
{{ form.as_p }}
<input type="button" value="New row" onclick="add_row()">
<table id="table_id">
<thead>
<tr>
<th>
Options
</th>
</tr>
</thead>
<tbody id="body">
</tbody>
</table>
<input type='submit' value='Submit'>
</form>
{% endblock %}
어떻게 선택 요소에서 데이터를 얻을 수 있습니다? 감사!! 편집 : 요청 요소를 확인했으며 request.post에 원하는 데이터가 없습니다.
문제의 해결책은 "name"속성 인 "value"속성과 별도로 설정할 수 있습니다. – mic4ael
이름과 ID를 모두 추가했지만 여전히 아무 것도 얻지 못했습니다 ... 어쨌든 고마워요! – Alvaro