简体   繁体   中英

Dojo DropDownMenu, class not found

i'm trying to make a menu, I cant even run this example code for some reason! The error on firbug is :

Could not load class "dijit.DropDownMenu"

Every other dojo menu related class is working, i tested that by removing parts of the code below to see if anything else is not rendering.

<div data-dojo-type="dijit.MenuBar" id="actionMenu">
<div data-dojo-type="dijit.PopupMenuBarItem">
    <span>File</span>
    <div data-dojo-type="dijit.DropDownMenu" id="fileMenu">
        <div data-dojo-type="dijit.MenuItem" data-dojo-props="onClick:function(){alert('file 1');}">File #1</div>
        <div data-dojo-type="dijit.MenuItem" data-dojo-props="onClick:function(){alert('file 2');}">File #2</div>
    </div>
</div>
<div data-dojo-type="dijit.PopupMenuBarItem">
    <span>Edit</span>
    <div data-dojo-type="dijit.DropDownMenu" id="editMenu">
        <div data-dojo-type="dijit.MenuItem" data-dojo-props="onClick:function(){alert('edit 1');}">Edit #1</div>
        <div data-dojo-type="dijit.MenuItem" data-dojo-props="onClick:function(){alert('edit 2');}">Edit #2</div>
    </div>
</div>

Can anyone point out why? I've used the follwoing require statements

dojo.require("dijit.MenuBar");
dojo.require("dijit.PopupMenuBarItem");
dojo.require("dijit.DropDownMenu");
dojo.require("dijit.MenuItem");

You haven't provided the information on how you get the library reference nor the version. So I'll assume it's googleapi's as that was the only way to get similar error.

The truth is, that while you reference the library from let's say googleapi's it doesn't work. I've tried to use 1.6 and less down to 1.2. No luck. Simply, that reference to dojo library doesn't contain a DropDownMenu definition.

The solution is to not use the googleapis :) Download the source cod version of Dojo from their download page and use the reference to that build. It worked for me for version 1.7.2. Or use some other links rather than google's

Hope this helps.

<html>
<head>
    <link rel="stylesheet" type="text/css" href="dojo172/dijit/themes/claro/claro.css" />  
    <link rel="stylesheet" type="text/css" href="dojo172/dojo/resources/dojo.css" />
    <script type="text/javascript">djConfig = { parseOnLoad:true, isDebug:true };</script>
    <script type="text/javascript" src="dojo172/dojo/dojo.js"></script>
    <script>
        dojo.require("dijit.DropDownMenu");
        dojo.require("dijit.MenuItem");
        dojo.require("dijit.MenuSeparator");
        dojo.require("dijit.PopupMenuItem");
        dojo.require("dijit.MenuBar");
</script>
</head>
<body class="claro">

<div data-dojo-type="dijit.DropDownMenu" id="navMenu">
    <div data-dojo-type="dijit.MenuItem" data-dojo-props="iconClass:'dijitEditorIcon dijitEditorIconCut',
        onClick:function(){alert('drama!')}">Drama</div>
    <div data-dojo-type="dijit.MenuItem" data-dojo-props="iconClass:'dijitEditorIcon dijitEditorIconCopy',
        onClick:function(){alert('comedy!')}">Comedy</div>
    <div data-dojo-type="dijit.MenuItem" data-dojo-props="iconClass:'dijitEditorIcon dijitEditorIconPaste',
        onClick:function(){alert('romance!')}">Romance</div>
    <div data-dojo-type="dijit.MenuSeparator"></div>
    <div data-dojo-type="dijit.PopupMenuItem">
        <span>Action</span>
        <div data-dojo-type="dijit.DropDownMenu" id="submenu2">
            <div data-dojo-type="dijit.MenuItem" data-dojo-props="onClick:function(){alert('diehard!')}">Diehard</div>
            <div data-dojo-type="dijit.MenuItem" onclick="alert('indiana!')">Indiana Jones</div>
        </div>
    </div>
</div>


</body>
</html>

When you get a class not found in Dojo:

  1. What class is not found? See if you are requiring the JS file that contains it.
  2. If not, add the necessary require. If you already are, continue:
  3. Check firebug net console: Is the file being requested at all?
  4. If not, look and make sure your require is executing. Fix it if not.
  5. If your file is being requested, but is erring out (404, etc), check where it is looking for the file
  6. Figure out why it can't find the file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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