English 中文(简体)
dojo.require 如果不允许地方变量
原标题:dojo.requireIf does not allow local variables
  • 时间:2009-12-14 06:37:46
  •  标签:
  • dojo

我正在尝试使用<代码>dojo.require(If),其中含有一个地方变量,以动态方式将一个基于条件页的单元装上。

// note: dojo v1.4
djConfig = {
  debugAtAllCosts: true
};

<>Exstrong>Example 1 (does not work):

(function() {
  var nameOfClass = "Two";
  dojo.require("my.namespace." + nameOfClass);
  dojo.addOnLoad(function() {
    var oneOrTwo = new my.namespace[nameOfClass]();
  });
}());

Error: ReferenceError: nameOfClass is not defined.

<>Exstrong>Example 2 (does not work):

(function() {
  var nameOfClass = "Two";
  dojo.requireIf(nameOfClass == "One", "my.namespace.One");
  dojo.requireIf(nameOfClass == "Two", "my.namespace.Two");
  dojo.addOnLoad(function() {
    var oneOrTwo = new my.namespace[nameOfClass]();
  });
}());

Error: ReferenceError: nameOfClass is not defined.

www.un.org/Depts/DGACM/index_french.htm

(function() {
  window.nameOfClass = "Two";
  dojo.requireIf(window.nameOfClass == "One", "my.namespace.One");
  dojo.requireIf(window.nameOfClass == "Two", "my.namespace.Two");
  dojo.addOnLoad(function() {
    var oneOrTwo = new my.namespace[nameOfClass]();
  });
}());

出于某种原因,它似乎既需要又需要。 如果只允许其中的全球变量。 这是否是一种目前的限制,还是我刚刚做过错?


<>Update 1

因此,如果我正确理解你(@Maine,@jrburke)的话,这是对德布古斯塔斯的限制? 如果上述法典是作为交叉主体制定的(处理Xd文档预设文件/文件),并且已经执行——它将按预期运作?

如果情况是这样,那么在不实际建造的情况下,作为交叉主实施的当地测试法的恰当方式是什么?

这也使我怀疑预先安排工作的动力。 如果装货人(或者说不能)预先准备,为什么为测试/拆卸而建立的方法?

<>Update 2

由于上文增编1中的两个问题与这个问题没有密切关系,我将其移至

最佳回答

页: 1 要求If与标准一致,作为第一件事,并在正常方案流程之前执行。

如果需要的话,请填满Dojo来源 如果你发现这种处理线(载荷_xd.js):

var depRegExp = /dojo.(require|requireIf|provide|requireAfterIf|platformRequire|requireLocalization)s*(([wW]*?))/mg;

该条件随后在全球范围以<代码>eval执行,而不是作为正常流动的一部分。

问题回答

为了进一步澄清主言,这是与Dojo的XD装载商的一个问题。 debugAt AllCosts: real use the XD Loader. 如果你只使用普通的Dojo装载器而不去除,这不是一个问题。 此外,将单元名称作为公开可见的单元中的财产,也将避免这一问题。





相关问题
Get Dojo Radio Button Value?

I have an HTML form using dojo and have the following code for a radio button selection choice: dojo.require("dijit.form.RadioButton"); <link href="http://ajax.googleapis.com/ajax/libs/dojo/1....

is it possible to know if a dijit is displayed or not?

i have two divs on a page. each has several dijits. i have atoggle that shows only one div or the other. when i submit the form, i only want to validate the dijits that are in the div that is ...

dijit BorderContainer auto-grow

Is there a way to have a dijit.layout.BorderContainer auto-grow in height? I ve tried setting min-height: 200px; height: auto;, but it won t scale. I ve tried looking at the API, but that thing is a ...

Dojo Tabs as Custom Widgets

I ve created a number of widgets that are loaded as tab panes in a tabcontainer. Everything seems to work well, except I m getting different results when using my custom widgets vs. creating ...

What happened to Dojo DOH?

The Dojo Toolkit used to come with a testing facility called "Doh". It was in the /utils directory. Now when you download dojo-release-1.3.2 the /utils directory is nowhere to be found. Is Doh dead ...

热门标签