TAGS :Viewed: 2 - Published at: a few seconds ago

[ Dojo accessing variable from external Javascript file ]

I am migrating to Dojo 10.4, before I have few customized javascript files which are modified by running dojo amd converter. But after migrating I cannot able to access variables in js files.

I have declared like this in a file called abc:

define([ "dojo", "dojo/_base/declare", "dojo/_base/lang", "dojo/on", "dojo/request", "dijit/form/FilteringSelect" ], function (dojo, declare, lang, on, request, FilteringSelect) { var VARIABLE= {};

Now I am using this js file in jsp file by integrating with <script>command.

the main problem is, how can I access the var VARIABLE in the jsp file.

I have tried with require, provide etc..but still cannot access the declared variable.

Answer 1


If you worked with javascript objects, then you can understand:

Here var VARIABLE is defined as a private variable, if you need it in JSP, you have to make it public. Here is an example snippet for it.

in ui/some.js:

define([
    "dojo/_base/declare",
    "dojo/_base/lang",
    "dijit/form/FilteringSelect"
],function( declare, lang, FilteringSelect){
    return declare("ui.some", [],{
        VARIABLE: "testing",
    });
});

In index.jsp:

require(["ui/some"],function(Some){
    alert(Some.VARIABLE);
});