0

I have created a dojo based Worklight project and a hybrid application it. I did a drag and drop of a dojo mobile button which gets added inside a dojo mobile view. All of this works fine and renders fine in the various environments (common, android etc.). It also correctly shows the look and feel in Rich Page Editor.

But then i added a script that has a very simple dojo.ready call. Now when i run this application i get a console error saying ReferenceError: dojo is not defined. Any idea why that is happening?

I know that i have correctly setup the dojo as other pieces seem to work. I have also checked that the dojo.js is loading (which is obvious as the other pieces are working). I am using IBM Worklight 6.0 developer edition with all capabilities installed.

Here is my sample code

<!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>

Thanks, Gaurav

1 Answers1

0

If you want to use dojo.ready you must initialize it first.

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

Here's the reference : http://dojotoolkit.org/reference-guide/1.8/dojo/ready.html#dojo-ready

Update 1

Which Version of dojo do you use by now? 1.6 or 1.7+ ? The new AMD requires to initialize the modules like i write before.

Have you read this threads? There seem to be an failure while importing the dojo Libarys. I guess this could have something to do with your error.

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

and

Worklight core-web-layer.js errors

Regards, Miriam

Community
  • 1
  • 1
MiBrock
  • 1,100
  • 1
  • 11
  • 22
  • Hi. Thanks for your reply. But as i know dojo app in Worklight doesn't add any specific require tags. Infact if you DnD a mobile widget, it isn't adding the require statements in the html but they do render correctly. On a sidenote even dojo.addOnLoad throws the same error. – Gaurav Bhattacharjee Aug 27 '13 at 09:22
  • Edit my answer and add two links. Maybe this helps. – MiBrock Aug 27 '13 at 10:14
  • That's because the DnD is probably using the deprecated way of coding where everything worked with `dojo.*`. I don't recommend using it this way. – g00glen00b Aug 27 '13 at 10:18
  • Have a look : http://dojotoolkit.org/documentation/tutorials/1.9/mobile/tweetview/getting_started/ – MiBrock Aug 27 '13 at 10:35
  • When you DnD a widget from the palette, it adds the necessary modules to the requires list that is in the application's JavaScript file (in this case `js/jmdwl.js`), not the application's html file. – nsand Aug 27 '13 at 13:23
  • @nsand : True that. I do have the require statements in the application's js file. Thanks. – Gaurav Bhattacharjee Aug 29 '13 at 14:01