Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我如何加上“;“满负荷”;去我的道场课?_Javascript_Dojo_Widget_Onload - Fatal编程技术网

Javascript 我如何加上“;“满负荷”;去我的道场课?

Javascript 我如何加上“;“满负荷”;去我的道场课?,javascript,dojo,widget,onload,Javascript,Dojo,Widget,Onload,我想在我的自定义Dojo类中添加一个“onload”函数,这样它就可以调用为事件注册到的函数,比如myWidget.addOnLoad(…) 我的类不是Dijit,而是一个使用dojo.declare的简单类。创建时,调用几个函数(xhr等)来初始化类,我需要能够通知其他javascript函数小部件已加载并准备就绪。因此我继续&基本上复制了Dojo addOnLoad函数并将其添加到我的类中。它似乎起作用了。我看了一下酒吧/酒吧或dojo.connect,但我觉得这是最干净、最容易识别的解决方

我想在我的自定义Dojo类中添加一个“onload”函数,这样它就可以调用为事件注册到的函数,比如myWidget.addOnLoad(…)


我的类不是Dijit,而是一个使用dojo.declare的简单类。创建时,调用几个函数(xhr等)来初始化类,我需要能够通知其他javascript函数小部件已加载并准备就绪。

因此我继续&基本上复制了Dojo addOnLoad函数并将其添加到我的类中。它似乎起作用了。我看了一下酒吧/酒吧或dojo.connect,但我觉得这是最干净、最容易识别的解决方案

下面是运行它所必需的部分,再次从dojo.js中剥离并插入到我的类中:

_onto : function(arr, obj, fn){
    if(!fn){
        arr.push(obj);
    }else if(fn){
        var func = (typeof fn == "string") ? obj[fn] : fn;
        arr.push(function(){ func.call(obj); });
    }
},

_loaded : function() {
    this._loadNotifying = true;
    this._postLoad = true;
    var mll = this._loaders;
    for(var x = 0; x < mll.length; x++){
        try{
            mll[x]();
        }catch(e){
            throw e;
            console.error("addOnLoad callback failed: " + e, e); /* let other load events fire, like the parser, but report the error */
        }
    }
    this._loadNotifying = false;
    //Make sure nothing else got added to the onload queue
    //after this first run. If something did, and we are not waiting for any
    //more inflight resources, run again.
    if(this._postLoad && this._inFlightCount == 0 && mll.length){
        this._loaded();
    }
},

addOnLoad : function(/*Object?*/obj, /*String|Function?*/functionName){
    this._onto(this._loaders, obj, functionName);   
    if(this._postLoad && !this._loadNotifying){
        this._loaded();
    }
}
\u到:功能(arr、obj、fn){
如果(!fn){
方位推力(obj);
}否则如果(fn){
var func=(typeof fn=“string”)?对象[fn]:fn;
arr.push(function(){func.call(obj);});
}
},
_已加载:函数(){
这是。_loadNotifying=true;
这是。_postLoad=true;
var mll=此。\装载机;
对于(变量x=0;x
所以我继续&基本上复制了Dojo addOnLoad函数并将其添加到我的类中。它似乎起作用了。我看了一下酒吧/酒吧或dojo.connect,但我觉得这是最干净、最容易识别的解决方案

下面是运行它所必需的部分,再次从dojo.js中剥离并插入到我的类中:

_onto : function(arr, obj, fn){
    if(!fn){
        arr.push(obj);
    }else if(fn){
        var func = (typeof fn == "string") ? obj[fn] : fn;
        arr.push(function(){ func.call(obj); });
    }
},

_loaded : function() {
    this._loadNotifying = true;
    this._postLoad = true;
    var mll = this._loaders;
    for(var x = 0; x < mll.length; x++){
        try{
            mll[x]();
        }catch(e){
            throw e;
            console.error("addOnLoad callback failed: " + e, e); /* let other load events fire, like the parser, but report the error */
        }
    }
    this._loadNotifying = false;
    //Make sure nothing else got added to the onload queue
    //after this first run. If something did, and we are not waiting for any
    //more inflight resources, run again.
    if(this._postLoad && this._inFlightCount == 0 && mll.length){
        this._loaded();
    }
},

addOnLoad : function(/*Object?*/obj, /*String|Function?*/functionName){
    this._onto(this._loaders, obj, functionName);   
    if(this._postLoad && !this._loadNotifying){
        this._loaded();
    }
}
\u到:功能(arr、obj、fn){
如果(!fn){
方位推力(obj);
}否则如果(fn){
var func=(typeof fn=“string”)?对象[fn]:fn;
arr.push(function(){func.call(obj);});
}
},
_已加载:函数(){
这是。_loadNotifying=true;
这是。_postLoad=true;
var mll=此。\装载机;
对于(变量x=0;x
您是否考虑过在小部件准备就绪时使用dojo.publish()发布主题?或者,如果其他代码引用了小部件,则可以在加载小部件时调用小部件实例上的空函数(称之为“加载”),然后引用该实例的其他代码可以dojo.connect连接到该小部件实例的“加载”方法在调用该方法时获得通知。

您是否考虑过在小部件准备就绪时使用dojo.publish()发布主题?或者,如果其他代码引用了小部件,则可以在加载小部件时调用小部件实例上的空函数(称之为“加载”),然后引用该实例的其他代码可以dojo.connect连接到该小部件实例的“加载”方法,以便在调用该方法时获得通知。

因为Dojo使您更容易:Dojo.connect是您所需要的全部。下面是一个例子:

a = {
    loaded: function() { console.log('[a] loaded'); }
}
b = {
    dependentAction: function() { console.log('[b] dependentAction'); }
}
dojo.connect( a, 'loaded', b, 'dependentAction' );
a.loaded()
// prints:
// [a] loaded
// [b] dependentAction
加载完
a
后,只需执行
a.loaded()
,因为Dojo让您变得简单:Dojo.connect就是您所需要的全部。下面是一个例子:

a = {
    loaded: function() { console.log('[a] loaded'); }
}
b = {
    dependentAction: function() { console.log('[b] dependentAction'); }
}
dojo.connect( a, 'loaded', b, 'dependentAction' );
a.loaded()
// prints:
// [a] loaded
// [b] dependentAction

然后在加载完
a
之后执行
a.loaded()

我看不出这是怎么回事。你是在调用这个代码示例之外的_loaded吗?seth你是对的,我在调用它之前没有调用运行的大量代码。_loaded()-可以说,当所有代码都运行完后,它会被调用。我不知道这会如何工作。你是在调用这个代码示例之外的_loaded吗?seth你是对的,在调用这个之前,我省去了运行的大量代码。_loaded()-可以说,当所有代码都运行完后,它就会被调用。缅因州,谢谢你提供了清晰的示例。我仍将使用addOnLoaded作为入口点,但只调用了dojo.connect(),而不是.main,感谢您提供了清晰的示例。我仍将使用addOnLoaded作为入口点,但只调用dojo.connect()。