Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.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';已完成事件的数据';s函数_Javascript_Jquery - Fatal编程技术网

访问javascript';已完成事件的数据';s函数

访问javascript';已完成事件的数据';s函数,javascript,jquery,Javascript,Jquery,我使用的是jQuery插件,它有一个名为completeCallback的事件 var filename = ui.file.name || ""; // Filename property may be absent when adding custom data // We can call preventDefault() method of event to cancel adding if (!isTextFile(ui.file) && !isImgFile(ui.

我使用的是jQuery插件,它有一个名为
completeCallback
的事件

var filename = ui.file.name || ""; // Filename property may be absent when adding custom data

// We can call preventDefault() method of event to cancel adding
if (!isTextFile(ui.file) && !isImgFile(ui.file)) {
    log(filename + ": is not image. Only images & plain text files accepted!");
    e.preventDefault();
    return ;
}

// We can replace original filename if needed
if (!filename.length) {
    ui.replaceName = "custom-data";
} else if (filename.length > 14) {
    ui.replaceName = filename.substr(0, 10) + "_" + filename.substr(filename.lastIndexOf('.'));
}
在下一段代码中,我将调用以下函数:

// code before...
    ui.completeCallback = function(success, data, errorCode) {
        if (success) {              
            console.log(this);
        }
    };
// code after...
将其输出到控制台,我想访问突出显示的行:

我怎样才能在
结束时做到这一点?
我知道如何访问类似于
this.id
的东西,它返回我
cbigtzl

谢谢你的帮助

==更新====

而.js的源代码在这里-几乎与我的相同: . 搜索
ui.completeCallback
部分

===更新2==== 以下是console.log输出: 在中向下滚动显示此示例。我假设您的
//code before…
是('du.add'
上的
,这意味着应该通过
此.file.name
访问它

$fileInput.on('du.add', function(e) {
    console.log('File added: ' + e.uploadItem.file.name);
    e.uploadItem.completeCallback = function(succ, data, status) {
        console.log(this.file.name + " was uploaded. Recieved data: ", data)
    };
});
在第二个链接的源代码中,您还可以看到变量
filename
填充在带有
ui.completeCallback
的部分中

var filename = ui.file.name || ""; // Filename property may be absent when adding custom data

// We can call preventDefault() method of event to cancel adding
if (!isTextFile(ui.file) && !isImgFile(ui.file)) {
    log(filename + ": is not image. Only images & plain text files accepted!");
    e.preventDefault();
    return ;
}

// We can replace original filename if needed
if (!filename.length) {
    ui.replaceName = "custom-data";
} else if (filename.length > 14) {
    ui.replaceName = filename.substr(0, 10) + "_" + filename.substr(filename.lastIndexOf('.'));
}

我们需要更多信息。什么插件?可能它有一个函数来获取文件名。@dystroy-不,它不起作用,已经尝试过了。newboyhun-我更新了这个问题,请检查一下你是否使用angular?$scope.Closure?我猜
filenameNew
是函数关闭的变量的名称。控制台出于调试目的,您好,但是词法闭包的原则之一是将这些变量设置为私有。@aspirinemaga恐怕是这样,至少不是从函数中。很抱歉,我无法正确理解您的答案,但我还是要问-这是否意味着无法访问它?thanks@aspirinemaga您正在发回
filenameNe吗服务器端的w
?如果是,你能用服务器的响应更新问题吗?@aspirinemaga如果是这样,你能
console.log(data)
,因为这应该是服务器的响应文本。