简体   繁体   English

Dojo从外部Javascript文件访问变量

[英]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. 我要迁移到Dojo 10.4,然后才能通过运行dojo amd转换器修改一些自定义的javascript文件。 But after migrating I cannot able to access variables in js files. 但是在迁移之后,我无法访问js文件中的变量。

I have declared like this in a file called abc: 我在一个名为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. 现在,我通过与<script>命令集成在jsp文件中使用此js文件。

the main problem is, how can I access the var VARIABLE in the jsp file. 主要问题是,如何访问jsp文件中的var VARIABLE。

I have tried with require, provide etc..but still cannot access the declared variable. 我尝试了require,provide等。但是仍然无法访问声明的变量。

If you worked with javascript objects, then you can understand: 如果您使用javascript对象,则可以理解:

Here var VARIABLE is defined as a private variable, if you need it in JSP, you have to make it public. 此处将var VARIABLE定义为私有变量,如果在JSP中需要它,则必须将其公开。 Here is an example snippet for it. 这是一个示例片段。

in ui/some.js: 在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: 在index.jsp中:

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

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

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