在下面的代码中,我试图向标签添加一个下拉框。为此,我调用了一个函数onready,然后添加它。我这里有两个问题
1.表格有两千多行,我使用django分页。但是准备好下拉框填充了所有两千行。我如何加载100行的下拉框,即正在分页. 这样它会更快。2.Also下拉框显示数据选择较慢。我该如何纠正这个。
希望我对这个问题很清楚
{% extends "base/admin_base.html" %}
{% load pagination_tags %}
{% block content %}
<script>
$(document).ready(function() {
$('font').css({'color':'red'})
getcategory('1');
});
function getcategory(flag)
{
if($("#cgroup").val().trim() == "-1")
{
alertmsg+= "Select Category group\n"
}
else
{
var html = "";
var opt = "";
var cgroup = $("#cgroup").val();
html += '<select id="category" class="category">';
html += '<option value="-1" class="cat">Select Category</option>';
{% for category in response_dict.category %}
gp = '{{category.categorygroup.id}}' ;
if(cgroup == gp)
{
html += '<option class="data" value="{{category.id}}">{{category.name}}</option>';
}
{% endfor %}
html += '</select>';
if(flag == 1)
{
$(".tg").html('');
$(".tg").append(html);
}
}
}
</script>
<h1>Tag data</h1>
{% autopaginate response_dict.taggeddata 100 %}
<div align="right">{% paginate %}</div>
<form action="/users/saveuser/" method="post">{% csrf_token %}
<table>
<tr><td><font>*</font>Select Category group for tagging</td><td>
<select id="cgroup" onchange="getcategory('1');">
{% for group in response_dict.categorygroup %}
<option value="{{group.id}}">{{group.name}}</option>
{% endfor %}
</select>
</td></tr>
</table>
<b>
<table>
<tr><td><font>*</font>Select Category group for tagging</td><td>
<select id="cgroup" onchange="getcategory('1');">
{% for group in response_dict.categorygroup %}
<option value="{{group.id}}">{{group.name}}</option>
{% endfor %}
</select>
</td></tr>
</table>
</b>
<table id="box-table-a">
<colgroup>
<col class="vzebra-odd">
</colgroup>
<thead>
<tr><th id="vzebra-comedy" scope="col">Field1</th><th id="vzebra-adventure" scope="col">Field2</th><th id="vzebra-comedy" scope="col">Field3</th><th id="vzebra-adventure" scope="col">Field4</th><th id="vzebra-comedy" scope="col">Field5</th><th id="vzebra-adventure" scope="col">Field6</th><th id="vzebra-comedy" scope="col">Tag</th><th id="vzebra-adventure" scope="col">Actions</th><thead></tr>
<tbody>
{% for td in response_dict.taggeddata %}
<tr id="{{td.id}}">
<td class="tg">Select category</td>
</tr>
{% endfor %}
</tbody>
</table>
<input type="button" value="Add" id="addbtn" onclick="validate();"/>
</form>
{% endblock %}