Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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_Arrays_Scope - Fatal编程技术网

JavaScript数组失去作用域且未传递到我的函数

JavaScript数组失去作用域且未传递到我的函数,javascript,arrays,scope,Javascript,Arrays,Scope,我正在创建一个数组作为TAFFYDB()查询的结果(但任何数组都可以) 我试着在函数调用中传递它 $("#submissionInput").fadeOut(function(){ $("#anaInputs").load("data/stubs/csaReport.html").promise().done(function(ret){ console.log(ret.length); // shows 1 ?? 我想这是因为我用了承诺或其他巫术。 为什么我失去了视

我正在创建一个数组作为TAFFYDB()查询的结果(但任何数组都可以)

我试着在函数调用中传递它

$("#submissionInput").fadeOut(function(){
    $("#anaInputs").load("data/stubs/csaReport.html").promise().done(function(ret){
        console.log(ret.length);  // shows 1 ??
我想这是因为我用了承诺或其他巫术。
为什么我失去了视野

您确定不需要先将其传递给外部函数吗?像这样:

$("#submissionInput").fadeOut(function(ret){
    $("#anaInputs").load("data/stubs/csaReport.html").promise().done(function(ret){
        console.log(ret.length);  // shows 1 ??

reg
ret
是不同的变量。什么是
reg
?将其替换为
ret
对不起,这是一个打字错误。在我的代码中到处都是“ret”在你发布代码后数组是否发生了变异?没有。我必须手动重新键入一些代码以进行澄清,并且有一个打字错误。我已经修复了它。console.log(ret.length);正确显示外部函数调用后的2对不起-您是正确的。你让ret超载了。换句话说,它恰恰相反。删除传入done方法的ret变量。e、 g.$(“#anaInputs”).load(“data/stubs/csaReport.html”).promise().done(function()){
$("#submissionInput").fadeOut(function(ret){
    $("#anaInputs").load("data/stubs/csaReport.html").promise().done(function(ret){
        console.log(ret.length);  // shows 1 ??