【问题标题】:-Dojo- Getting the name of the file, that I want to upload-Dojo- 获取我要上传的文件名
【发布时间】:2016-02-24 10:19:25
【问题描述】:

所以我上传了一个文件。上传文件后,我想获得它的名称,如“picture.jpg”或“test.jar”。我想要这个名字,因为我想把它放在一个文本框中。

这是我的代码:

var up = new dojox.form.Uploader({
    id:"up",
    label: 'Select jar File',
    multiple: false,
    url: '/echo/json/'
}).placeAt(uploadDialog);

var list = new dojox.form.uploader.FileList({
    id:"fileList",
    uploader: up
}).placeAt(uploadDialog);

var btn = new button({
    type: 'submit',
    label: 'upload',
    onClick: function() {
        up.upload();
    }
}).placeAt(uploadDialog);

//Close button
    closeButton3 =new button({label:"close",placement:"special",id:"closebtn3",class:"buttons"});

    daspect.after(closeButton3,"onClick",function(){ //Event closeButton
    uploadDialog.hide();
    var filename = document.getElementById("fileList").value;
    console.log(filename);
    });
    closeButton3.placeAt(uploadDialog,"last");


btn.startup();
up.startup();
list.startup();     
closeButton3.startup();

该 URL 不起作用,但目前这应该不是问题(我希望如此)。

非常感谢!

【问题讨论】:

  • 您是否尝试过在调试器中检查“列表”对象?从内存中(使用它 3 年),它包含本机 File 对象,其中包含文件名的值
  • 谢谢!现在我有了对象。所以我创建了一个新变量: var filename = up2.getFileList();!
  • 没问题 :) 用你的想法回答你自己的问题,它可能会帮助其他人

标签: file file-upload upload dojo filenames


【解决方案1】:

问题解决了!

要获取名称(具有“名称”属性的对象),您可以轻松使用函数。

我的上传器被称为“up”,所以我将使用以下代码获取(我要上传的)对象:

var filename = up2.getFileList();//创建一个对象

【讨论】:

    猜你喜欢
    • 2013-05-04
    • 1970-01-01
    • 2017-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多