0

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

上传回调:

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 对象未定义。我已经能够通过同一个控制器在其他功能中使用builderChild对象,但在uploadSuccess中不行。

有任何想法吗?

4

1 回答 1

0

试试这个,我以前就是这样的。

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

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

希望这有帮助

于 2012-09-11T18:15:46.440 回答