开发者

Setting up Dojo Release 1.5.0

I donwloaded this release, and I'm trying to run an example开发者_如何学C from the docs. After expanding the Dojo download, my dojo dir is:

js/dojo-release-1.5.0/dijit
js/dojo-release-1.5.0/dojo
js/dojo-release-1.5.0/dojox

The buttons show up, but hide button does not hide the div. Do I need to add other Dojo libraries along with the reference to dojo.js?

<script type="text/javascript" language="JavaScript"  src="/js/dojo-release-1.5.0/dojo/dojo.js"></script>

<script type="text/javascript">

dojo.require("dijit.form.Button");

dojo.addOnLoad(function() {
    var node = dojo.byId("findMe");
    dojo.connect(dijit.byId("buttonOne"), "onClick", function() {
        dojo.fadeOut({
            node: node,
            duration: 300
        }).play();
    });
    dojo.connect(dijit.byId("buttonTwo"), "onClick", function() {
        dojo.fadeIn({
            node: node,
            duration: 300
        }).play();
    })
});

HTML:

<button dojoType="dijit.form.Button" id="buttonOne">
Hide Me!
</button>
<button dojoType="dijit.form.Button" id="buttonTwo">
Show Me!
</button>
<div id="findMe">
Hiya!
</div>


There are a couple of things you may be missing. As Daniel says, adding parseOnLoad=true as a djConfig param will help. Alternatively you can add djConfig params as a global JS variable before your dojo.js script tag, i.e.

<script>
  var djConfig = {
    parseOnLoad: true
  }
</script>

A final alternative is to manually call the parser yourself. To do this, modify your JS to:

dojo.require("dijit.form.Button");
// You need to manually require the parser if you're going to call it yourself
dojo.require("dojo.parser");

dojo.addOnLoad(function() {
    var node = dojo.byId("findMe");
    dojo.connect(dijit.byId("buttonOne"), "onClick", function() {
        dojo.fadeOut({
            node: node,
            duration: 300
        }).play();
    });
    dojo.connect(dijit.byId("buttonTwo"), "onClick", function() {
        dojo.fadeIn({
            node: node,
            duration: 300
        }).play();
    })

    // New line, parse the doc
    dojo.parser.parse();
});

Additionally to parsing, you may need to add a theme (you've not mentioned if you've done this or not). The easiest way to do this is to add the class name to your body tag and import the css.

    ...
    <link rel="stylesheet" type="text/css" href="/js/dojo-release-1.5.0/dijit/themes/claro/claro.css">
</head>
<body class="claro">
  ...
</body>

http://telliott.net/dojoExamples/dojo-buttonHelloWorld.html contains an example of this all working for you, feel free to go crib.

Reading http://dojotoolkit.org/reference-guide/djConfig.html#djconfig and http://dojotoolkit.org/reference-guide/dijit/info.html#dijit-info would probably be a good idea also.

HTH.

Tom


try adding djConfig="parseOnLoad:true" when add the dojo.js to the page.

ex:

<script type="text/javascript" language="JavaScript"  src="/js/dojo-release-1.5.0/dojo/dojo.js" djConfig="parseOnLoad:true"></script>

//Daniel

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜