2

我想从 dojo 1.7 更新到 1.8.3,所以我必须替换 dojo.connect 命令。

转变:

< div id="universalPushSwitch" data-dojo-type="dojox.mobile.Switch" style="float:right" class="mblSwRoundShape1"></div>

我现在有:

dojo.require("dijit/registry");
dojo.require("dojo/ready");
dojo.require("dojox/mobile/ListItem");
dojo.require("dojo/aspect");

dojo.ready(function(){
  dojo.aspect.after(dijit.registry.byId("universalPushSwitch"), "onStateChanged", 
        function(newState){
        alert(newState);
    }
)});

Firebug 说:“方面未定义”

PS:我知道我不使用新的 AMD 加载程序。这是一个旧项目,我对所有 dojo 的东西也很陌生。一个简单的从dojo.require("x");dojo.require("y");to翻译require(["x","y"], function (x,y){...}对我不起作用,所以仍然需要旧样式。

4

2 回答 2

3

尝试使用:

dojo.aspect.after(...);

代替

aspect.after(...);

并且不要停留在下一个功能!:-)

如果这不能立即起作用,请尝试以全局方式加载方面(使用点,而不是斜线):

dojo.require("dojo.aspect");

也有可能,旧的道场与“/”不兼容,它只适用于点!

来源:

http://livedocs.dojotoolkit.org/dojo/require

编辑

这是一个基于您的小提琴的工作小提琴:

http://jsfiddle.net/9Xdv2/

The main problem with your code was that you did not parse the html. dojo parser converts some specific html to "dojo javascript objects" ! You use that kind of html a lot ! You should have done a:

dojox.mobile.parser.parse();

Everything is in the jsfiddle !

于 2013-04-09T08:09:16.770 回答
2

Since you are using dojo 1.8.3 and have been using dojo 1.7, why don't you use the AMD syntax instead of the pre-1.7 ? You would do something like :

<div id="universalPushSwitch" data-dojo-type="dojox/mobile/Switch" style="float:right" class="mblSwRoundShape1"></div>

And in your js :

require(["dijit/registry",
         "dojox/mobile/ListItem",
         "dojo/aspect",
         "dojo/parser",
         "dojo/domReady!"
         ], function(registry, ListItem, aspect, parser){

    parser.parse().then(function(instances){
        aspect.after(registry.byId("universalPushSwitch"), "onStateChanged", 
           function(newState){
               alert(newState);
           });
    });
});
于 2013-04-09T13:02:49.957 回答