Select to view content in your preferred language

question about dojo.registerModulePath in ags_js_api

1653
3
11-22-2011 11:21 PM
taopy
by
Deactivated User
in dojo setting ,For instance, if �??/web/scripts/dojo/dojo/dojo.js�?� is the path to dojo.js, and you do dojo.require(�??some.module�?�), Dojo will try to load the JavaScript file using the path �??/web/scripts/dojo/some/module.js�?�.  but  what about this in ags_js_api?
in my application  ,i used dojo.provide a resource named "custom/config.js" and put "custom/config.js" in the dojo folder,like this: http://forums.arcgis.com/attachment.php?attachmentid=10309&stc=1&d=1322039729

but it throws error when i  use dojo.require("custom.config") ,
error like this pic: http://forums.arcgis.com/attachment.php?attachmentid=10310&stc=1&d=1322039897

thx for your help!
0 Kudos
3 Replies
derekswingley1
Deactivated User
Your screen shot doesn't match the scenario you're describing...are you sure you're specifying your paths correctly? For instance, you talk about �??/web/scripts/dojo/dojo/dojo.js�?� but your screen shot shows "js/dojo/dojo".

How are you specifying your module path? Can you post the code you're using to define your module paths?

I recommend reading up on how this works in dojo: 
http://dojotoolkit.org/reference-guide/dojo/registerModulePath.html

Also look into using modulePaths via dojoConfig/djConfig.
0 Kudos
by Anonymous User
Not applicable
Original User: steeeeps

Your screen shot doesn't match the scenario you're describing...are you sure you're specifying your paths correctly? For instance, you talk about �??/web/scripts/dojo/dojo/dojo.js�?� but your screen shot shows "js/dojo/dojo".

How are you specifying your module path? Can you post the code you're using to define your module paths?

I recommend reading up on how this works in dojo: 
http://dojotoolkit.org/reference-guide/dojo/registerModulePath.html

Also look into using modulePaths via dojoConfig/djConfig.



ok  i am sorry that  what  i have described was  not  the  same with my screen  shot ,this time i give you my code and the right screen shot :
my custon class:
if (!dojo._hasResource["custom.config"]) {
    dojo._hasResource["custom.config"] = true;
    dojo.provide("custom.config");
    dojo.declare("custom.Config", null, {
        constructor: function(){
        }
    });
    dojo.mixin(custom.Config, {
        configPath: "conf/config.txt",
        configObj: null,
        parseConfig: function(load, error){
            dojo.xhrGet({
                url: this.configPath,
                handleAs: "json",
                load: load,
                error: error
            });
        }
        
    });
}

my index.html where i require my custom class:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title>index.html</title>
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="this is my page">
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
        <link rel="stylesheet" type="text/css" href="css/main.css">
        <link rel="stylesheet" type="text/css" href="js/arcgis_js_api/library/2.4/arcgis/js/dojo/dijit/themes/claro/claro.css">
        <link rel="stylesheet" type="text/css" href="js/arcgis_js_api/library/2.4/arcgis/js/dojo/dojox/grid/resources/claroGrid.css">
        <script type="text/javascript" src="js/arcgis_js_api/library/2.4/arcgis/">
        </script>
        <script type="text/javascript">
            djConfig = {
                parseOnLoad: true
            };
        </script>
        <script type="text/javascript">
            dojo.require("esri.map");
            dojo.registerModulePath("custom", "../../custom");
            dojo.require("custom.config");  //this line throw error....
            
            function init(){
                console.log(custom.Config.configPath);
            }
            
            dojo.addOnLoad(init);
        </script>
    </head>
    <body class="claro">
        <div id="headContainer">
            <div id="head">
            </div>
        </div>
    </body>
</html>


the picture named 1.png is  the screen shot of the custom path .
the picture named 2.png is the wrong in the firebug of the code "dojo.require("custom.config");".

and i have another  question can you help me ?
i opened the source code in esri.js ,and i saw the line "_1.registerModulePath("esri", (location.protocol === 'file:' ? 'http:' : location.protocol) + '//' + "localhost:8080/cd/js/arcgis_js_api/library/2.4/arcgis/js/esri");" so i think ,this line is the  reason why we can use the classes in packge esri  directly like "dojo.require("esri.map")",it use the absolute  path.
then i changed my code like this :
  dojo.registerModulePath("custom", "http://localhost:8080/cd/js/arcgis_js_api/library/2.4/arcgis/js/custom");
,now the line  "dojo.require("custom.config")" throw no error ,but this page also throw an error like this: "NetworkError: 404 Not Found - http://localhost:8080/cd/js/arcgis_js_api/library/2.4/arcgis/js/custom/config.xd.js"  my question is that why my page want to get the custom.config.xd.js not the custom.config.js, i browsed in esri source code ,why every js file has two like geometry.js  and geometry.xd.js ,what is the role *.xd.js act ?

i have so many questions, so thx you  very much.
0 Kudos
taopy
by
Deactivated User
Your screen shot doesn't match the scenario you're describing...are you sure you're specifying your paths correctly? For instance, you talk about �??/web/scripts/dojo/dojo/dojo.js�?� but your screen shot shows "js/dojo/dojo".

How are you specifying your module path? Can you post the code you're using to define your module paths?

I recommend reading up on how this works in dojo: 
http://dojotoolkit.org/reference-guide/dojo/registerModulePath.html

Also look into using modulePaths via dojoConfig/djConfig.


i have solved my problem, thx a lot;
0 Kudos