添加具有重复ID'FileULoader'FileUploader的元素

时间:2014-08-25 07:31:47

标签: javascript file-upload sap sapui5

createContent : function(oController) {

        var oFileUploader  = new sap.ui.commons.FileUploader({
            id: "FileULoader",
        //uploadUrl : "UploadFileServelet",   // URL to submit the form to
        name: "simpleUploader",          // name of the input type=file element within the form 
    //  uploadOnChange: true,           // immediately upload the file after selection
        buttonOnly: false,
        buttonText: "Upload"
        }).addStyleClass("downloadBtn");
        oFileUploader.attachUploadComplete(oController.doFileLoadComplete);  
    //var uploadBtn=new sap.ui.commons.buttons{this.creatId("upLoadFile"),}



    var oMatrix = new sap.ui.commons.layout.MatrixLayout({
        layoutFixed : true,
        width : '400px',
        columns : 1 });

    var text = new sap.ui.commons.TextView({text:"Confirm that the data will be wiped out once you upload new data file."});

    oMatrix.createRow(oFileUploader);
    oMatrix.createRow(text);

    var oDialog = new sap.ui.commons.Dialog({
        title:"FileUpload",
        resizable:false,
        modal:true,
        showCloseButton:true,
        contentBorderDesign:"Box",
        content:[
                 oMatrix   
        ],
        buttons:[
            new sap.ui.commons.Button({text:"Confirm", tooltip:"Confirm",press:function(e){oController.doFileUpload();oDialog.close();}}),
            new sap.ui.commons.Button({text:"Cancel", tooltip:"Cancle",press:function(e){oDialog.close();}}),
        ]
    });
    return oDialog;

我在两个视图中使用过。当我调用fileUploader时,错误结果出来了。 我必须使用id来识别fileloder控制器。获取输入文件信息。

更新

_uploadCourse:function(){
    if (!this.dialogUploadFile) {
        this.dialogUploadFile = sap.ui.jsfragment("courseUP",
                "adminView.dialogUploadFile", this);
    }
    this.dialogUploadFile.open();
},
_uploadCourse : function() {

                    if (!this.dialogUploadFile) {
                        this.dialogUploadFile = sap.ui.jsfragment("certiUploadFile",
                                "adminView.dialogUploadFile", this);
                    }
                    this.dialogUploadFile.open();
                },

这就是我使用片段的方式。但是同样的错误仍然出错了; @Allen Zhang

2 个答案:

答案 0 :(得分:0)

您提到您在两个视图中使用了代码。您无法使用相同的Fileupload控件ID创建两次对话框。对不同的视图使用不同的ID。

更新:

定义片段用法的ID:

<core:Fragment id="myFrag" fragmentName='my.frag' type='JS' />

通过调用 createId

来定义fileupload id
var oFileUploader  = new sap.ui.commons.FileUploader({
        id: this.createId("FileULoader"),
    //uploadUrl : "UploadFileServelet",   // URL to submit the form to
    name: "simpleUploader",     // name of the input type=file element within the form 
//  uploadOnChange: true,           // immediately upload the file after selection
    buttonOnly: false,
    buttonText: "Upload"
    }).addStyleClass("downloadBtn");

另请参阅我对fragment usageget control inside fragment的解答。

答案 1 :(得分:0)

您是不是使用id作为文件上传器控件的选项,并且这样做吗?

createContent : function(oController) {
    this.oFileUploader = new sap.ui.commons.FileUploader({

要访问它,你可以

view.oFileUploader

其中view是两个视图之一的javascript句柄。

-D