我正在尝试使用 Django 使用 htmx 制作一个应用程序。
我创建了一个下拉列表:
<select class="custom-select mb-4" name="fields" hx-get="{% url 'select_field' %}" hx-trigger="change" hx-target="#Wells">
<option selected>Select a field</option>
{% for Field in TFTFields %}
<option ue="{{Field.Perimeter}}">{{Field.Perimeter}}</option>
{% endfor %}
</select>
现在我想从此列表中获取选定的值并将其传递给按钮以激发另一个名为“plotlybar”的函数,我做了这样的事情:
<button class="btn btn-primary" hx-get="{% url 'plotlybar' %}" hx-target="#plotlybar">Plot the bar Well Serv</button>
那么现在我不知道如何传递这个选定的项目?
有什么提示或解决方案吗?
尽我所能
您可以通过以下方式在 HTMX 请求中包含其他表单元素hx-include属性 https://htmx.org/attributes/hx-include/使用 CSS 查询选择器:
<button class="btn btn-primary"
hx-get="{% url 'plotlybar' %}"
hx-include="[name='fields']"
hx-target="#plotlybar">
Plot the bar Well Serv
</button>
如果要包含多个元素,请提供以逗号分隔的选择器列表,例如:[name='field1'], [name='field2']
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)