【问题标题】:When does Dojo need the args variable?Dojo 什么时候需要 args 变量?
【发布时间】:2010-11-05 19:03:20
【问题描述】:

你必须将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);

【问题讨论】:

  • 你必须更加明确。粘贴一些代码。
  • 我粘贴了一些代码。我想知道它是否会起作用。

标签: javascript ajax frameworks dojo


【解决方案1】:

澄清一下:您指的是代码示例中的args 参数,它是loaderror 回调函数定义的一部分:

如果你需要使用它,你只需要args 变量。 Dojo 本身不需要它。通常你不应该需要它。第一个参数应该是您要查找的结果。

但是,如果您需要访问原始的 XMLHttpRequest 对象,那么 args.xhr 将持有它。

同样,如果您想访问传递给 dojo.xhrGet 的原始对象(因为您在其上存储了某种状态),您可以通过 args.args 获取它(因此,我通常将该参数命名为 @ 987654329@,所以它会是ioArgs.args)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-16
    • 1970-01-01
    • 1970-01-01
    • 2018-12-10
    • 2010-12-29
    • 2017-07-13
    • 2012-08-21
    • 2011-08-18
    相关资源
    最近更新 更多