How to define Module and use it in dojo with AMD?
Posted
by
Devdatta Tengshe
on Stack Overflow
See other posts from Stack Overflow
or by Devdatta Tengshe
Published on 2013-06-25T05:22:57Z
Indexed on
2013/06/25
16:21 UTC
Read the original article
Hit count: 314
I am maintaining and extending an old project which was pre-AMD. I wish to add an Chart to the application. for this, I have created a js file as follows:
define(["dojox/charting/Chart",...."dijit/Dialog","dojo/dom-construct"],
function (Chart) {
function showDailyChart(data){
//code to show the chart in a dialog
}
return customModules.singleChart;
});
I have saved this file as /customModules/singleChart.js
In My main HTML Page, I have added it to the packages as follows:
var dojoConfig = { parseOnLoad: true,
packages: [....,{"name":"customModules",
"location":location.pathname.replace(/\/[^/]+$/, "")+"/modules" }
]};
The function from which I want to call it, is pre-AMD. So I am calling it as follows:
dojo.require("customModules.singleChart");
.
.
.
customModules.singleChart.showDailyChart(data);
I can see that /customModules/singleChart.js
is loaded in the Firebug console as well as Net Tab. However there is no customModules.singleChart
object. Strangely enough there is no error either. I have tested this in Firebug, as well as Google Chrome's developer tools.
What is the correct way to call an AMD Module using dojo.require
? Or is there a better way to do what I need?
© Stack Overflow or respective owner