你必须将args变量传递给匿名函数,但匿名函数显然并不需要args变量,所以你必须记住Dojo何时需要args变量,但Dojo帮助页面没有说!那么,Dojo 什么时候需要 args 变量呢?
var init = function(){
var contentNode = dojo.byId("content");
dojo.xhrGet({
url: "js/sample.txt",
handleAs: "text",
load: function(data,args){
// fade out the node we're modifying
dojo.fadeOut({
node: contentNode,
onEnd: function(){
// set the data, fade it back in
contentNode.innerHTML = data;
dojo.fadeIn({ node: contentNode }).play();
}
}).play();
},
// if any error occurs, it goes here:
error: function(error,args){
console.warn("error!",error);
}
});
};
dojo.addOnLoad(init);
最佳答案
澄清一下:您指的是 args
您的代码示例中的参数是 load
函数定义的一部分和error
回调:
您只需要args
变量,如果你需要使用它。 Dojo 本身并不需要它。通常你不需要它。第一个参数应该是您正在寻找的结果。
但是,如果您需要访问原始 XMLHttpRequest
对象,然后args.xhr
会持有它。
同样,如果您想访问传递给 dojo.xhrGet
的原始对象(因为你在上面存储了某种状态),你可以在 args.args
处获取它(出于这个原因,我通常将该参数命名为 ioArgs
,所以它就是 ioArgs.args
)。
关于javascript - Dojo 什么时候需要 args 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1043018/