目前我已经能够使用for循环,列出所有相关的url使用这个:
<H2> Your Visuals are located here: </H2>
<ul class="main-navigation"> {% for i,j in files%}
<H3>{{j}}</H3>
<ul>
<li><a href="{% url 'visualisation:network_multi_graphs' %}?database={{i}}">Multiple Graphs</a></li>
<li><a href="{% url 'visualisation:customer_locations' %}?database={{i}}">Customer Locations</a></li>
<li><a href="{% url 'visualisation:product_quantity' %}?database={{i}}">Product Quantity</a></li>
<li><a href="{% url 'visualisation:demand_time' %}?database={{i}}">Demand over Time Period</a></li>
</ul>
{% endfor %}
</ul>
我试图实现一个下拉菜单的所有链接使用下面的代码,只有一个链接作为测试,但似乎没有渲染。
<label>values in z<label>
<select id="the-id">
{% for i, j in files %}
<option value=" href="{% url 'visualisation:customer_locations' %}?database={{i}}">Customer Locations</option>
{% endfor %}
</select>
谁知道我在哪里搞砸了?使用新的解决方案编辑无效:
<style>
/* Dropdown Button */
.dropbtn {
background-color: #04AA6D;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #ddd;}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {display: block;}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {background-color: #3e8e41;}
</style>
<div class="dropdown">
<ul id="buttons"> {% for i,j in network_files %}
<div class="main-navigation">
<H2> Your Visuals are located here: </H2>
<H3>{{j}}</H3>
<ul>
<li><a href="{% url 'data_visualisation:network_multi_graphs' %}?database={{i}}">Multiple Graphs</a></li>
<li><a href="{% url 'data_visualisation:customer_locations' %}?database={{i}}">Customer Locations</a></li>
<li><a href="{% url 'data_visualisation:product_quantity' %}?database={{i}}">Product Quantity</a></li>
<li><a href="{% url 'data_visualisation:demand_time' %}?database={{i}}">Demand over Time Period</a></li>
</ul>
{% endfor %}
</div>
</div>
您将需要一点JavaScript,这不是我的强项。但是像这样的事情(依赖于可能有缺陷的记忆)
<select name="nextview" onchange="javascript:handleNextView(this)">
<option value="{% url ... %}">Multi Graphs</option>
<option value="{% url ... %}">Customer Locations</option>
<!-- etc ... -->
</select>
<script type="text/javascript">
function handleNextView(el){
window.location.assign( el.value ); /* redirect on select */
}
</script>