gpt4 book ai didi

javascript - 将变量传递给函数回调

转载 作者:行者123 更新时间:2023-11-29 19:58:12 24 4
gpt4 key购买 nike

如何获取 fileDoesNotExist 回调的变量、url 和名称:

window.checkIfFileExists = function(path, url, name) {
return window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, (function(fileSystem) {
return fileSystem.root.getFile(path, {
create: false
}, fileExists, fileDoesNotExist);
}), getFSFail);
};

fileDoesNotExist = (fileEntry, url, name) ->
downloadImage(url, name)

最佳答案

phoneGap的getFile函数有两个回调函数。您在这里使用 fileDoesNotExist 犯的错误是它应该调用两个函数,而不是引用一个变量。

像下面这样的东西会起作用:

window.checkIfFileExists = function(path, url, name) {
return window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, (function(fileSystem) {
return fileSystem.root.getFile(path, {
create: false
},
function(e) {
//this will be called in case of success
},
function(e) {
//this will be called in case of failure
//you can access path, url, name in here
});
}), getFSFail);
};

关于javascript - 将变量传递给函数回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15572223/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com