简体   繁体   English

如何在Dojo中获取当前文件名

[英]How to get current filename in dojo

How can I get the current file name I'm in, using dojo. 如何使用dojo获取当前所在的文件名。 I have a javascript file and my break point is within that file. 我有一个javascript文件,我的断点在该文件内。 I want to know the file name. 我想知道文件名。 and using dojo or javascipt I want to get the name of this file 并使用dojo或javascipt我想要获取此文件的名称

Any Help will be highly appreciated Thank you 任何帮助将不胜感激谢谢

If you are using AMD (Dojo 1.7+) you can get the module ID of the current module from the special module module: 如果使用的是AMD(Dojo 1.7+),则可以从特殊module模块中获取当前模块的模块ID:

define([ 'module' ], function (module) {
  console.log(module.id);
});

If using legacy Dojo modules, the filename of the script currently being executed is never provided and cannot be retrieved in a cross-browser way because they are loaded using XHR and eval . 如果使用旧版Dojo模块,则永远不会提供当前正在执行的脚本的文件名,也无法以跨浏览器的方式检索该文件名,因为它们是使用XHR和eval加载的。

There is an example of that in dojo/tests/_base/loader/moduleIds.js : 在dojo / tests / _base / loader / moduleIds.js中有一个示例:

function get(mid, refmod){
    return require.getModuleInfo(mid, refmod, require.packs, require.modules, "../../dojo/", require.mapProgs, require.pathsMapProg, 1);
}

I tried the following in one of my modules : 我在其中一个模块中尝试了以下操作:

require.getModuleInfo("my/Module", null, require.packs, require.modules, "../../dojo/", require.mapProgs, require.pathsMapProg, 1).url

This resolved the path to the javascript file that contains my module code... 这解决了包含我的模块代码的javascript文件的路径...

This works too : 这也可行:

require.modules["my/module"].url

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM