我想使用select2.min.js
自动完成选择(ForeignKey值),但是它仅适用于我的第一种形式,我对重复的形式使用了django形式集
这是我的摘录
<tbody class="tbody tb1 " id="form_set">
{% for item in items.forms %}
<tr class="p-0 col-12">
<td class="">
<div class="col-12 p-0 mt-3 inp">
<input class="col-12 0qarz qarz" type="number" name="" placeholder="qarz">
</div>
</td>
<td class="">
<div class="col-12 p-0 mt-3 inp">
{{item.price | add_class:'col-12 '}}
</div>
</td>
<td class="">
<div class="col-12 p-0 mt-3 inp">
{{item.quantity | add_class:'col-12 '}}
</div>
</td>
<td class="">
<div class="col-12 p-0 mt-3 inp">
{{item.model | add_class:'col-12 0model model' | attr:'id:model'}}
</div>
</td>
</tr>
{% endfor %}
</tbody>
<script type="text/javascript">
$(function(){
$('.tb1 tr:last').formset({
prefix:'{{items.prefix}}',
addText:'add',
deleteText:'remove',
addCssClass:'btn btn-success',
});
})
</script>
<script type="text/javascript">
$(document).ready(function(){
$("#model").select2()
})
</script>
但是select2仅适用于我的第一种形式,然后对其他形式没有任何影响!以及如何将表格数量设置为add_class
,这可能有助于解决?谢谢
首先,我希望看到更多信息,例如您实际定义表单集的方式。我也不清楚您要在这里做什么。请粘贴更多数据。
我建议您考虑使用django-select2模块,该模块在处理django中的select2方面有很大帮助。
我也不知道您所说的“如何设置表格数量”是什么意思,也许您希望在for / endfor循环中包含一些可以通过{{ forloop }}
完成的递增计数器?
请粘贴更多的东西,答案会更好。