dojo.ready调用在Worklight 6.0中显示错误

时间:2013-08-27 04:59:34

标签: dojo ibm-mobilefirst

我创建了一个基于dojo的Worklight项目和一个混合应用程序。 我做了一个dojo移动按钮的拖放,它被添加到dojo移动视图中。所有这一切都很好,并在各种环境(普通,Android等)中呈现良好。它还在Rich Page Editor中正确显示外观。

但后来我添加了一个脚本,它有一个非常简单的dojo.ready调用。现在,当我运行此应用程序时,我收到一个控制台错误,指出 ReferenceError:未定义dojo 。知道为什么会这样吗?

我知道我已经正确设置了dojo,因为其他部分似乎有效。我还检查了dojo.js是否正在加载(这很明显,因为其他部分正在工作)。我正在使用安装了所有功能的IBM Worklight 6.0开发人员版本。

这是我的示例代码

<!DOCTYPE HTML>
<html>
        <head>
            <meta charset="UTF-8">
            <title>jmdwl</title>
            <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
            <meta name="apple-mobile-web-app-capable" content="yes">
            <link rel="shortcut icon" href="images/favicon.png">
            <link rel="apple-touch-icon" href="images/apple-touch-icon.png">
            <link rel="stylesheet" href="css/jmdwl.css">
            <script>window.$ = window.jQuery = WLJQ;</script>
            <script type="text/javascript" src="dojox/mobile/deviceTheme.js"></script>
            <script type="text/javascript" data-dojo-config="isDebug: false, async: true, parseOnLoad: true, mblHideAddressBar: false" src="dojo/dojo.js"></script>
            <script>
            dojo.ready(function() {
                alert("Here");
            });
            </script>
        </head>
        <body id="content" style="display: none;">
            <div data-dojo-type="dojox.mobile.ScrollableView" id="view0" data-dojo-props="selected:true">
                <!--application UI goes here-->

                    <button data-dojo-type="dojox.mobile.Button">Label</button>
            </div>
            <script src="js/initOptions.js"></script>
            <script src="js/jmdwl.js"></script>
            <script src="js/messages.js"></script>
        </body>
</html>

谢谢, 拉夫

1 个答案:

答案 0 :(得分:0)

如果你想使用dojo.ready,你必须先将它初始化。

<script>
  require(["dojo/ready"], function(ready){     
        ready(function() {
            alert("Here");
        });
  });

以下是参考:http://dojotoolkit.org/reference-guide/1.8/dojo/ready.html#dojo-ready

更新1

你现在使用哪个版本的道场? 1.6或1.7+? 新的AMD要求像我之前写的那样初始化模块。

你读过这个帖子吗?导入dojo Libarys时似乎有失败。我想这可能与你的错误有关。

worklight fail to require DOJO Combobx on real device -fail to load ... /dijit/form/nls/it/ComboBox.js

Worklight core-web-layer.js errors

此致,Miriam