2013-04-10 113 views
2

我正在嘗試使用cordova File API在我的worklight項目中創建一個文件。我得到的錯誤,參考錯誤:LocalFileSystem未定義

Reference Error: LocalFileSystem not defined

我試過使用下面的鏈接解決方案,但仍然我得到相同的錯誤。我應該在我的js文件夾中添加任何腳本文件嗎?我不知道從哪裏得到確切的cordova.js文件。 PhoneGap- Android FileSystem Requesting Error

當我包括cordova.js文件,我得到的錯誤 enter image description here

這裏是我的代碼:

document.addEventListener("ondeviceready", onDeviceReady(), true); 
function onDeviceReady() { 
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail); 
} 

function onFileSystemSuccess(fileSystem) { 
    alert(fileSystem.name+" created"); 
    alert(fileSystem.root.name); 
} 

function fail(evt) { 
    alert(evt.target.error.code); 
} 

}

+0

你能分享你的代碼嗎?確保在deviceready事件觸發後使用LocalFileSystem。 – wmfairuz 2013-04-10 07:51:13

+0

我已更新與我的代碼在問題..請讓我knw,如果你想進一步的任何其他信息... – 2013-04-10 08:27:26

回答

1
document.addEventListener("ondeviceready", onDeviceReady(), true); 

這是不對的。這意味着你將該函數的返回值作爲參數。你只需要把這個函數的名字。改用它。 (不包括())

document.addEventListener("ondeviceready", onDeviceReady, true); 
+0

嗨,我試着做這兩個..我仍然得到同樣的錯誤.. – 2013-04-12 04:03:46

+0

我hace相同的問題 – Harry 2013-06-27 08:30:41

+0

我也面臨同樣的問題。任何人解決它請幫助我 – 2013-07-01 10:21:09

0

也許你沒有安裝文件系統插件,嘗試科爾多瓦插件之後添加org.apache.cordova.file命令。