window.requestFileSystem当代触发'成功'和'错误'回调?

时间:2013-03-21 20:55:32

标签: javascript html5

我省略了一些代码,但这是核心:

function App() {

var self = this;

window.requestFileSystem(LocalFileSystem.PERSISTENT, 
                          0, self.onGotFs, self.onError(1) );


... omitted ....


this.onGotFs = function(file_system) {
    console.log("gotFs:" + file_system.root.full_path );
    self.file_system = file_system;
};

this.onError = function(id) {
    console.log("app error #" + id);
};


    ... omittted ...

}

查看控制台我看到了两条消息

app error #1
gotFs ! 

请注意:我无法看到file_system.root.full_path字符串。它不是主打

所以主要的问题是:

为什么requestFileSystem会触发成功和错误回调?

可能我错过了一些知识库;我是一个html5新手

文档

我在w3c documentation - paragraph 4.4.1

上看到了这个定义
interface LocalFileSystem {
    const unsigned short TEMPORARY = 0;
    const unsigned short PERSISTENT = 1;
    void requestFileSystem (unsigned short type, unsigned long long size, FileSystemCallback successCallback, optional ErrorCallback errorCallback);
    void resolveLocalFileSystemURL (DOMString url, EntryCallback successCallback, optional ErrorCallback errorCallback);
};

1 个答案:

答案 0 :(得分:1)

self.onError(1)

立即调用onError 并将结果传递给requestFileSystem

您需要传递一个调用onError

的函数
requestFileSystem(..., function() { self.onError(1); });

此外,使用错误的onGotFs调用this。您可以传递类似的功能或传递self.onGotFs.bind(self)

相关问题