简体   繁体   English

Umbraco Cms 中的下拉菜单

[英]Dropdown menu in Umbraco Cms

This is my Master layout page.这是我的主布局页面。 I am generating the dynamic menu, but clicking the dropdown does not show any items.我正在生成动态菜单,但单击下拉菜单没有显示任何项目。 What am I doing wrong?我究竟做错了什么?

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Master>
@using ContentModels = Umbraco.Web.PublishedContentModels;
@{
    Layout = null;
}
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>@Umbraco.Field("siteTitle")</title>
        <meta name="description" content="@Umbraco.Field("metaDescription", recursive: true)">
        <meta name="keyword" content="@Umbraco.Field("metaKeywords", recursive: true)">
        <link href="~/Content/bootstrap.css" rel="stylesheet" />

          <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
     </head>
     <body>

This is the start of the navigation section.这是导航部分的开始。

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      @{ IPublishedContent root = Model.Content.AncestorOrSelf(1); }
      <ul class="nav navbar-nav">     
        <li class="@((Model.Content.Name == root.Name) ? "active" : null)">
            <a href="/">@root.Name</a></li>
        </li>
        @foreach (IPublishedContent menuItem in root.Children.Where(x => x.IsVisible())) {
            <li class="@((menuItem.Name == Model.Content.Name) ? "active" : null)">
                <a href="@menuItem.Url">@menuItem.Name</a>
            </li>
        }

This is where the code starts to not work.这是代码开始不起作用的地方。

        <li class="dropdown">
          <a class="dropdown-toggle" data-toggle="dropdown" href='@Model.Content.AncestorOrSelf(1).Children.Where(x => x.DocumentTypeAlias == "projectsMain")'>Our Proj<span class="caret"></span></a>
          <ul class="dropdown-menu">
            @{
              IQueryable projectsDropdown =
                Model.Content.AncestorOrSelf(1)
                .Children
                .Where(x => x.DocumentTypeAlias == "projectsMain")
                .First()
                .Children
                .Where("Visible")
                .OrderBy("Name");

            }
            @foreach(IPublishedContent project in projectsDropdown){
                                var prevalue = project.GetPropertyValue<int>("projectStatus");
                                if(Umbraco.GetPreValueAsString(prevalue) == "Completed"){
                                    <li><a href="@project.Url">@project.Name</a></li>
                                }
                            }
          </ul>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

        @RenderBody();

        <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <!-- Include all compiled plugins (below), or include individual files as needed -->
        <script src="~/Scripts/bootstrap.js"></script>
        <script src="~/Scripts/bootstrap.min.js"></script>
        <script src="~/Scripts/jquery-2.2.0.min.js"></script>
     </body>
</html>

Have you tried debugging your way through?你有没有试过调试你的方式? Have you checked the generated HTML source to see if there actually are items in the dropdown-menu ul?您是否检查了生成的 HTML 源代码以查看下拉菜单 ul 中是否真的有项目?

Which Umbraco version are you using?您使用的是哪个 Umbraco 版本? Looks like 7.x - so there are much easier ways to do some of what you do.看起来像 7.x - 所以有更简单的方法来完成你所做的一些事情。 Like @CurrentPage.Site() to get root node.像@CurrentPage.Site() 来获取根节点。

You are including both bootstrap.js and bootstrap.min.js, that might mess things up, as well as including what looks like two versions of jQuery?您同时包括 bootstrap.js 和 bootstrap.min.js,这可能会搞砸,还包括看起来像两个版本的 jQuery?

Also, you are including (the jquery-2.2.0.js) jQuery after bootstrap.js, that might also cause problems.此外,您在 bootstrap.js 之后包含(jquery-2.2.0.js)jQuery,这也可能会导致问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM