Native Phonegap、下载并创建文件、动态命名文件和返回路径

Native Phonegap, download and createfile, dynamicly named file, and return path

本文关键字:文件 返回路径 动态 创建 Phonegap 下载 Native      更新时间:2023-11-16

问题在于我对Javascript afaik缺乏了解。当我写:

function startOnDevice(){
   var path = document.addEventListener("deviceready", onDeviceReady, true);
}

然后,我如何传递文件名的"字符串"?(ei。到DeviceReady,然后再往下树。

然后在它已经被传递到onDeviceReady之后。它需要在FSSuccess:上传递给

function onDeviceReady() {
//what do we have in cache already?
$("#status").html("Checking your local cache....");    
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFSSuccess, null);    
}
function onFSSuccess(fileSystem) {
    fileSystem.root.getDirectory("dk.lector.html5Generic",{
        create:true
    },gotDir,onError);
}

然后onFSSuccess需要以某种方式将值返回给变量路径。

有什么帮助吗?

好的,这是一个新版本,因为您已经更新了问题中的代码:

var file = "foo.txt";
function onDeviceReady() {
  //what do we have in cache already?
  $("#status").html("Checking your local cache....");
  alert("file is " + file);    
  window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, 
  function (fileSystem) {
    onFSSuccess(fileSystem, file); // use file variable from above and pass as second param.
  }, null);    
}
function onFSSuccess(fileSystem, file) {
  alert("file is " + file);
  fileSystem.root.getDirectory("dk.lector.html5Generic",{
    create:true
   },gotDir,onError);
}