【问题标题】:How can I get the View in the FileTransfer upload method in PhoneGap?如何在PhoneGap的FileTransfer上传方法中获取View?
【发布时间】:2012-09-12 02:15:46
【问题描述】:

我使用 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中不行。

有什么想法吗?

【问题讨论】:

    标签: android cordova sencha-touch-2


    【解决方案1】:

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

    var ftSuccess = Ext.bind(this.uploadSuccess, this),
        ftError   = Ext.bind(this.uploadError, this);
    
    fileTransfer.upload(imageURI, uri, ftSuccess, ftError, options);        
    

    希望对你有所帮助

    【讨论】:

    • 这也可以,但是我的问题只是解码响应。 Ext.decode(r.response)
    • 我也用this.uploadSuccess.bind(this)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-29
    • 1970-01-01
    相关资源
    最近更新 更多