本文介绍了Dojo不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < link rel =stylesheettype =text / csshref =http://ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo/resources/dojo.css>< / link> 
< link rel =stylesheettype =text / csshref =http://ajax.googleapis.com/ajax/libs/dojo/1.9.1/dijit/themes/tundra/tundra。 CSS>< /链路>
< link rel =stylesheettype =text / csshref =../../../../ resources / themes / default / styles / layout.cssth:href = @ {/资源/默认/风格/ layout.css中} >< /链路>
< script type =text / javascriptsrc =http://ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo/dojo.jsdata-dojo-config = parseOnLoad:真>< /脚本>

< script type =text / javascriptsrc =../../../ resources / dev / scripts / Spring.jsth:src =@ {/ resources /弹簧/ Spring.js}>< /脚本>
< script type =text / javascriptsrc =../../../ resources / dev / scripts / Spring-Dojo.jsth:src =@ {/ resources / spring /弹簧的dojo.js}>< /脚本>


< div id =gridContainerstyle =width:100%; height:400px;>< / div>

< script type =text / javascript>
dojo.require('dojo.store.JsonRest');
dojo.require('dijit.layout.ContentPane');
dojo.require(dijit.form.Button);
dojo.require('dojox.grid.DataGrid');
dojo.require('dojo.data.ObjectStore');
dojo.require('dijit.form.TextBox');
dojo.require('dojox.data.AndOrReadStore');
dojo.require('dojo._base.xhr');
dojo.require('dojo.json')
dojo.require('dojo.domReady');

dojo.ready(function(){

var appLayout = new dijit.layout.ContentPane({
id:appLayout
} appLayout);

var textBox = new dijit.form.TextBox({
name:searchbox,
placeHolder:Search ...


textBox.placeAt('appLayout');
appLayout.placeAt('gridContainer');

appLayout.startup();
});
< / script>

firefox告诉我有一个错误:



$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ ined ined ined ined ined ined ined ined ined ined ined ined ined ined ined ined ined ined ined ined ined ined ined ined ined ined =[object Object],undefined =appLayout)_WidgetBase.js(línea4)
(undefined =[object Object],undefined =appLayout)dojo.js(línea 104)
()home(línea16)
()dojo.js(línea237)
()dojo.js(línea236)
(undefined =1000) dojo.js(línea237)
[Detener en este error] b._contentSetter&& b._contentSetter.par ... = u.getLocalization(dijit,loading,

任何帮助将不胜感激。

解决方案

你正在做一些奇怪的事情,我想,你想要一个 TextBox 里面一个 ContentPane ,如果我不对,请忘记以下答案。



此代码有几个错误:



你创建你的 appLayout contentpane,你提供了第二个参数(你用来将appLayout此参数用于定义应用于放置内容窗格的DOM节点(或DOM节点的ID)。您不要拥有名为 appLayout 的I​​D节点。有关更多信息,请参阅,该文档说第二个参数是 srcNodeRef 。解决方案是将此参数留空。



然后第二个错误是您将 TextBox 放在甚至在它被放置在DOM本身并启动之前的 ContentPane 。所以重新安排你的代码,所以 ContentPane 首先放在网格容器上。



完整的代码,更改:

  dojo.require('dojo.store.JsonRest'); 
dojo.require('dijit.layout.ContentPane');
dojo.require(dijit.form.Button);
dojo.require('dojox.grid.DataGrid');
dojo.require('dojo.data.ObjectStore');
dojo.require('dijit.form.TextBox');
dojo.require('dojox.data.AndOrReadStore');
dojo.require('dojo._base.xhr');
dojo.require('dojo.json')
dojo.require('dojo.domReady');

dojo.ready(function(){

var appLayout = new dijit.layout.ContentPane({
id:appLayout
}) ;
appLayout.placeAt('gridContainer');
appLayout.startup();

var textBox = new dijit.form.TextBox({
name:搜索框,
placeHolder:搜索...
});
textBox.placeAt('appLayout');
});

或作为。
启动可能不需要放置TextBox,但现在代码分组更好一些。



我也想建议更新您的代码以使用异步语法(Dojo 1.7+),因为您使用的语法自从1.7以来已被弃用,并且自从使用1.9以来,我没有看到使用旧语法编写新代码的任何好处,因为它不会在Dojo 2.0中工作。


I am new at dojo and here is my code:

    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo/resources/dojo.css"></link>
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.1/dijit/themes/tundra/tundra.css"></link>
    <link rel="stylesheet" type="text/css" href="../../../../resources/themes/default/styles/layout.css" th:href="@{/resources/default/styles/layout.css}"></link>  
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo/dojo.js" data-dojo-config="parseOnLoad:true"></script>

    <script type="text/javascript" src="../../../resources/dev/scripts/Spring.js" th:src="@{/resources/spring/Spring.js}"></script>
    <script type="text/javascript" src="../../../resources/dev/scripts/Spring-Dojo.js" th:src="@{/resources/spring/Spring-Dojo.js}"></script>


 <div id="gridContainer" style="width: 100%; height: 400px;"></div>

    <script type="text/javascript">
        dojo.require('dojo.store.JsonRest');
        dojo.require('dijit.layout.ContentPane');
        dojo.require("dijit.form.Button");
        dojo.require('dojox.grid.DataGrid');
        dojo.require('dojo.data.ObjectStore');
        dojo.require('dijit.form.TextBox');
        dojo.require('dojox.data.AndOrReadStore');
        dojo.require('dojo._base.xhr');
        dojo.require('dojo.json')
        dojo.require('dojo.domReady');

        dojo.ready(function() {

            var appLayout = new dijit.layout.ContentPane({
                            id: "appLayout"
                            }, "appLayout");

            var textBox = new dijit.form.TextBox({
                        name: "searchbox",
                        placeHolder: "Search ..."
                        });

            textBox.placeAt('appLayout');              
            appLayout.placeAt('gridContainer');

            appLayout.startup();     
        });
    </script>

firefox tells me that there is an error:

TypeError: d is null
(undefined="[object Object]", undefined="null")ContentPane.js (línea 4)
(undefined="[object Object]", undefined=""appLayout"")_WidgetBase.js (línea 4)
(undefined="[object Object]", undefined=""appLayout"")dojo.js (línea 104)
()home (línea 16)
()dojo.js (línea 237)
()dojo.js (línea 236)
(undefined="1000")dojo.js (línea 237)
[Detener en este error] b._contentSetter&&b._contentSetter.par...=u.getLocalization("dijit","loading",

any help would be appreciated.

解决方案

You're doing some strange things. What I suppose is that you want a TextBox inside a ContentPane, if i'm not right, then forget the following answer.

There are several mistakes in this code:

While creating your appLayout contentpane, you're providing the second argument (which you use to put "appLayout" in. This argument is used to define the DOM node (or the ID of the DOM node) that should be used to place the contentpane at. You don't have a DOM node with an ID called appLayout. For more information look at the API documention which says that the second parameter is the srcNodeRef. The solution is to leave this parameter empty.

Then the second mistake is that you're placing the TextBox inside the ContentPane even before it was placed on the DOM itself and started up. So re-arranging your code so the ContentPane is placed on the grid container first will work.

The complete code, with changes:

dojo.require('dojo.store.JsonRest');
dojo.require('dijit.layout.ContentPane');
dojo.require("dijit.form.Button");
dojo.require('dojox.grid.DataGrid');
dojo.require('dojo.data.ObjectStore');
dojo.require('dijit.form.TextBox');
dojo.require('dojox.data.AndOrReadStore');
dojo.require('dojo._base.xhr');
dojo.require('dojo.json')
dojo.require('dojo.domReady');

dojo.ready(function() {

    var appLayout = new dijit.layout.ContentPane({
        id: "appLayout"
    });
    appLayout.placeAt('gridContainer');
    appLayout.startup();

    var textBox = new dijit.form.TextBox({
        name: "searchbox",
        placeHolder: "Search ..."
    });
    textBox.placeAt('appLayout');              
});

Or as a JSFiddle.The startup is probably not required to be able to place the TextBox, but now the code is grouped a bit better.

I would also like to suggest to update your code to use the asynchronous syntax (Dojo 1.7+) since the syntax you're using is deprecated since 1.7 and since you're using 1.9 I don't see any benefit from writing new code with the old syntax since it will not work in Dojo 2.0.

这篇关于Dojo不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 11:27