1

我已经制作了一个 dojo 构建,但我希望在启用/禁用构建时具有灵活性,所以我尝试<script>在 HTML 标头中加载标签:

<script src="js/config.js"></script>
<script src="/dojo/1.9/dojo/dojo.js" data-dojo-config="async: true"></script>
<script src="/dojo/1.9/dojo/dojo-all.js"></script>

我没有修改我的 JS 文件。它似乎起作用,但是,有一个问题,但仅限于 IE9,并且仅限于部署在 WebSphere 上的应用程序版本(我已经在 Apache2 上测试过)。问题是,在那个特定的代码片段中,属性“dir”是未定义的:

    geom.isBodyLtr = function isBodyLtr(doc) {
        doc = doc || win.doc;
        return (win.body(doc).dir || doc.documentElement.dir 
           || "ltr").toLowerCase() == "ltr";
    };

在搜索了一些类似的问题后(​​例如:How to prevent "Unable to get value of the property 'dir': object is null or undefined" error when loading pages in IE9),我检测到它可能是一些加载顺序问题。我已经从 HTML 标头中删除了该层,并按以下顺序将其加载到我的 JS 中:

require(["dojo/domReady!"], function(){
// load the layers, but only after document is ready
require(['dojo/dojo-all'], function(){

require(["dojo", "dojo/on", "dojo/dom-attr", "dojo/dom-class", (... and hundred more) 

但是,我知道人们正在 HTML 标头中加载构建,例如从这里的主题:Dojo Builds...?现在怎么办?

所以我的问题是,我是不是做错了什么,或者 HTML 标头的技巧不能保证在所有浏览器上都有效?

这是我的构建脚本配置:

'dojo/dojo': {         
    include: ['dojo/dojo', 'dojo/domReady', 'dojo/_base/declare'],         
    boot: true,         
    customBase: true    
},
'dojo/dojo-all': {
    include: ["dojo/on", "dojo/dom-attr", "dojo/dom-class", "dojo/query", "dojo/_base/lang", "dojo/request/xhr", 
    "dijit/registry","dijit/form/TextBox", "dijit/form/Textarea", "dijit/form/ComboBox", "dijit/form/FilteringSelect", "dijit/form/CheckBox", "dijit/form/Button",
    "gridx/core/model/cache/Sync", "gridx/Grid", "gridx/modules/SingleSort", "gridx/modules/ColumnResizer", 
    (...and hundred more)],
    boot: false, // exclude bootstrap modules
    customBase: false
},

这是dojo的build.bat:

java -Xms256m -Xmx256m  -cp "%~dp0../shrinksafe/js.jar";"%
~dp0../closureCompiler/compiler.jar";"%~dp0../shrinksafe/shrinksafe.jar" 
org.mozilla.javascript.tools.shell.Main  "%~dp0../../dojo/dojo.js" 
baseUrl="%~dp0../../dojo" load=build %*
4

1 回答 1

2

我们最近在加载图层文件的顺序方面遇到了同样的问题。要让它与 IE9 一起使用,您确实需要控制层文件加载的顺序,所以是的,最简单和最可靠的方法是加载require层文件而不是使用<script>加载它们。

查看此页面底部的示例,其中包含嵌套在另一个要求中的要求:

http://www.sitepen.com/blog/2012/06/11/dgrid-and-dojo-nano-build/

We've just made exactly the same changes in a product here to avoid sporadic failures with IE9 and IE10 (with 7 layer files, one of which needed to override an older version of a module defined in one of the others). <script> had seemingly worked fine for some time, but it turned out that we couldn't rely on it.

于 2013-07-30T14:24:46.773 回答