【问题标题】:Displaying django-cms submenu in an option element在选项元素中显示 django-cms 子菜单
【发布时间】:2013-09-02 23:05:54
【问题描述】:
【问题讨论】:
标签:
jquery
html
css
django
django-cms
【解决方案1】:
正如您自己所说,文档告诉您使用自定义模板,这正是您在这种情况下应该做的。
<select>
{% show_sub_menu 1 "option_menu.html" %}
</select>
然后在“option_menu.html”中:
{% for child in children %}
<option>{{ child.get_menu_title }}</option>
{% endfor %}
请注意,这只会显示一级子菜单,更多信息,请查看{% if child.children %},如果是True,请按照您的情况做您认为最好的事情。
【解决方案2】:
感谢您的回复。我实际上已经设法使用一些 JS 来做到这一点。我已将<li> 标签转换为<option> 这是代码:
<script type="text/javascript">
$(document).ready(function(){
$('.subnav').each(function() {
$(this).find('a').each(function() {
var $option = $('<option />');
$option.attr('value', $(this).attr('href')).html($(this).html());
$("#mobileNav").append($option);
});
});
$("#mobileNav").change(function(){
window.location.href = $(this).val();
});
});
</script>
我现在将尝试您的解决方案,因为它更简洁,但上面的代码将来可能对其他人有用。
再次感谢!