dojo / parser :: parse()错误TypeError:无法读取属性' getAttribute'未定义的

时间:2017-05-05 05:42:29

标签: javascript webforms dojo dijit.layout dijit.dialog

我正在使用带有.NET webforms的dojo来创建弹出菜单,当我尝试加载页面时,我收到以下错误。 " dojo / parser :: parse()错误TypeError:无法读取属性' getAttribute'未定义"

如果有人可以分享关于如何将dojo用于webforms的博客,那将非常有用。 以下是我的代码供参考。请检查并帮我解决此问题。

<%@ Page Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="xyz.aspx.cs" Inherits="xyz" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
<link href="../Content/bootstrap.min.css" rel="stylesheet" />
<link href="../Content/themes/base/jquery-ui.css" rel="stylesheet" />
<link href="../Content/claro.css" rel="stylesheet" />
<link href="../Scripts/dojo/resources/dojo.css" rel="stylesheet" />

<script type="text/javascript" src="../Scripts/jquery-1.12.4.js"></script>
<script type="text/javascript" src="../Scripts/bootstrap.min.js"></script>
<script type="text/javascript" src="../Scripts/jquery-ui-1.12.1.js">
</script>
<script type="text/javascript" src="../Scripts/dojo/dojo.js" ></script>

</head>
<body class="claro" style="height:100px;width:100px;">

 <div data-dojo-type="dijit/layout/BorderContainer" style="height:100%; width:100%">

        <div data-dojo-type="dijit/layout/ContentPane"
            data-dojo-props="region: 'center'">
            <div data-dojo-type="dijit/MenuBar">
                <div data-dojo-type="dijit/PopupMenuBarItem">
                    <span>File</span>
                    <div data-dojo-type="dijit/DropDownMenu">
                        <div data-dojo-type="dijit/MenuItem">Open</div>
                        <div data-dojo-type="dijit/MenuItem">Save</div>
                        <div data-dojo-type="dijit/PopupMenuItem">
                            <span> Recent...</span>
                        </div>
                    </div>
                </div>
            </div> 
        </div>
    </div>

 <script type="text/javascript">

     document.getElementById("pnlControlList").remove();
     $("#navbar").remove();

     require(["dojo/parser"], function (parser) {
         parser.parse();
     });

 </script>
</body>
</html>
</asp:Content> 

1 个答案:

答案 0 :(得分:0)

这段代码会导致问题:

<div data-dojo-type="dijit/PopupMenuItem">
   <span> Recent...</span>
</div>

dijit/PopupMenuItem需要包含dropdown元素作为其子元素。

require(["dojo/parser", 
  "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dijit/MenuBar", 
  "dijit/PopupMenuBarItem", "dijit/DropDownMenu", "dijit/MenuItem", "dijit/PopupMenuItem"
], function (parser) {
         parser.parse();
     });
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dijit/themes/claro/claro.css" />

<body class="claro">
<div data-dojo-type="dijit/layout/BorderContainer" style="height:100px; width:100px">

        <div data-dojo-type="dijit/layout/ContentPane"
            data-dojo-props="region: 'center'">
            <div data-dojo-type="dijit/MenuBar">
                <div data-dojo-type="dijit/PopupMenuBarItem">
                    <span>File</span>
                    <div data-dojo-type="dijit/DropDownMenu">
                        <div data-dojo-type="dijit/MenuItem">Open</div>
                        <div data-dojo-type="dijit/MenuItem">Save</div>
                        <div data-dojo-type="dijit/PopupMenuItem">
                            <span> Recent...</span>
                            <div data-dojo-type="dijit/DropDownMenu">
                              <div data-dojo-type="dijit/MenuItem">Some Item</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div> 
        </div>
    </div>
    </body>

注意:我还将html中包含的所有dijit模块添加到所需的模块中。我不知道它是否在.NET中是强制性的,但有些环境会在没有它的情况下抛出错误(例如jsfiddle)