【发布时间】:2013-11-19 19:30:10
【问题描述】:
我是 PhoneGap 的新手,正在尝试开发一个简单的应用程序来写入文本文件。我使用了使用 LocalFileSystem 的 PhoneGap 的文档。
// Cordova is loading
document.addEventListener("deviceready", onDeviceReady, false); // PhoneGap is fully loaded
// Cordova is ready
function onDeviceReady()
{
//alert('Hello');
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function fail(){
console.log('fail');
}
function gotFS(fileSystem) {
var path = "test.txt";
fileSystem.root.getFile(path, {create: true, exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.onwriteend = function(evt) {
console.log("contents of file now 'some sample text'");
writer.truncate(11);
writer.onwriteend = function(evt) {
console.log("contents of file now 'some sample'");
writer.seek(4);
writer.write(" different text");
writer.onwriteend = function(evt){
console.log("contents of file now 'some different text'");
}
};
};
writer.write("some sample text");
}
运行此代码时,我得到了 Uncaught ReferenceError: LocalFileSystem is not defined at 使用其他 Javascript 在其他对象上给我同样的错误(例如 ActiveXObject...)
谁能帮帮我?谢谢!
【问题讨论】: