Dojo 示例有效,但我的无效

Posted

技术标签:

【中文标题】Dojo 示例有效,但我的无效【英文标题】:Dojo Examples work but mine doesnt 【发布时间】:2016-03-05 21:17:37 【问题描述】:

所以我在练习,当我点击它时它会运行,但是当我将它复制并粘贴到我自己的文字处理器 (Atom) 并在选项卡中运行它时,它只是空白

require([
"dijit/MenuBar",
"dijit/PopupMenuBarItem",
"dijit/Menu",
"dijit/MenuItem",
"dijit/DropDownMenu",
"dojo/domReady!"
], function(MenuBar, PopupMenuBarItem, Menu, MenuItem, DropDownMenu)
var pMenuBar = new MenuBar();
var pSubMenu = new DropDownMenu();
pSubMenu.addChild(new MenuItem(
    label: "File item #1"
));
pSubMenu.addChild(new MenuItem(
    label: "File item #2"
));
pMenuBar.addChild(new PopupMenuBarItem(
    label: "File",
    popup: pSubMenu
));
var pSubMenu2 = new DropDownMenu();
pSubMenu2.addChild(new MenuItem(
    label: "Cut",
    iconClass: "dijitEditorIcon dijitEditorIconCut"
));
pSubMenu2.addChild(new MenuItem(
    label: "Copy",
    iconClass: "dijitEditorIcon dijitEditorIconCopy"
));
pSubMenu2.addChild(new MenuItem(
    label: "Paste",
    iconClass: "dijitEditorIcon dijitEditorIconPaste"
));
pMenuBar.addChild(new PopupMenuBarItem(
    label: "Edit",
    popup: pSubMenu2
));
pMenuBar.placeAt("wrapper");
pMenuBar.startup();
);
</script>
<div id="wrapper"></div>

反斜杠是句点没有问题。

【问题讨论】:

在执行上述脚本之前,您是否在某处加载dojo.js 对不起,我非常了解,我只是从示例代码中使用它。这就是所有被给予的。没有dojo.js。 【参考方案1】:

要真正获得可运行的东西,您需要的不仅仅是问题中发布的代码 sn-p。至少您需要加载 Dojo 加载程序 (dojo.js) 或等效的 AMD 加载程序——这就是 require 函数的来源。由于代码是使用 Dijit 创建菜单,因此您还需要加载基本 Dojo 样式表和 Dijit 主题(否则菜单看起来会很糟糕)。

主Dojo website有很多教程。 Hello Dojo! 是一个很好的入门方式。

<html>

<head>
  <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/resources/dojo.css">
  <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dijit/themes/claro/claro.css">
  <script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js" data-dojo-config="async:true"></script>
  <script>
    require([
      "dijit/MenuBar",
      "dijit/PopupMenuBarItem",
      "dijit/Menu",
      "dijit/MenuItem",
      "dijit/DropDownMenu",
      "dojo/domReady!"
    ], function(MenuBar, PopupMenuBarItem, Menu, MenuItem, DropDownMenu) 
      var pMenuBar = new MenuBar();
      var pSubMenu = new DropDownMenu();
      pSubMenu.addChild(new MenuItem(
        label: "File item #1"
      ));
      pSubMenu.addChild(new MenuItem(
        label: "File item #2"
      ));
      pMenuBar.addChild(new PopupMenuBarItem(
        label: "File",
        popup: pSubMenu
      ));
      var pSubMenu2 = new DropDownMenu();
      pSubMenu2.addChild(new MenuItem(
        label: "Cut",
        iconClass: "dijitEditorIcon dijitEditorIconCut"
      ));
      pSubMenu2.addChild(new MenuItem(
        label: "Copy",
        iconClass: "dijitEditorIcon dijitEditorIconCopy"
      ));
      pSubMenu2.addChild(new MenuItem(
        label: "Paste",
        iconClass: "dijitEditorIcon dijitEditorIconPaste"
      ));
      pMenuBar.addChild(new PopupMenuBarItem(
        label: "Edit",
        popup: pSubMenu2
      ));
      pMenuBar.placeAt("wrapper");
      pMenuBar.startup();
    );
  </script>
</head>

<body class="claro">
  <div id="wrapper"></div>
</body>

</html>

【讨论】:

以上是关于Dojo 示例有效,但我的无效的主要内容,如果未能解决你的问题,请参考以下文章

代码在 .Net 5 中有效,但在 .Net 6 中无效

Android蓝牙聊天示例无效,无法连接设备

处理 dojo gridx 中分页的更改事件

使用短划线分隔符进行RegEX 14位数验证

验证IP地址 - python [重复]

DOJO按钮示例[关闭]