如何在PhoneGap中的FileTransfer上传方法中获取View?

时间:2012-09-11 17:36:32

标签: android cordova sencha-touch-2

我已经使用PhoneGap + Sencha Touch 2创建了一个本机Android应用程序。我已成功将文件上传到服务器,但是,我在从FileTransfer upload()中的上传成功回调函数访问View时遇到问题方法。这是我的代码:

上传回调:

uploadPicture: function(imageURI) {
    var options = new FileUploadOptions(),
    params = new Object(),
    fileTransfer = new FileTransfer(),
    builder = this.getBuilder(),
    app = this.getApplication(),
    uri = encodeURI('/myservlet');

options.fileKey = 'file';
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType = 'image/jpeg';

params.myparams = something;
params.moreparams = evenmore;

options.params = params;
options.chunkedMode = false;

fileTransfer.upload(imageURI, uri, this.uploadSuccess.bind(this), this.uploadError.bind(this), options);        
},

上传成功功能

uploadSuccess: function (r) {
    var builderChild = this.getBuilderChild(),
    data = r.response.attachment;

builderChild.addInstance(builderChild.config, data);
navigator.notification.alert('Attachment successful.');
}

当我进入uploadSuccess函数时,我的builderChild对象是未定义的。我已经能够在其他函数中通过同一个Controller使用builderChild对象,但不能在uploadSuccess中使用。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

尝试一下,这就是我以前的做法。

var ftSuccess = Ext.bind(this.uploadSuccess, this),
    ftError   = Ext.bind(this.uploadError, this);

fileTransfer.upload(imageURI, uri, ftSuccess, ftError, options);        

希望这有帮助