简体   繁体   English

在valums ajax文件上传器中上传后清除文件列表

[英]Clear File listing after upload in valums ajax file uploader

I finally managed to get the valums file uploader working in all the browsers. 我终于设法使valums文件上载器在所有浏览器中都能正常工作。 Now once the file gets uploaded it still shows the file just uploaded in a li just below the file input field. 现在,一旦文件被上传,它仍会在文件输入字段下方的li中显示刚刚上传的文件。 I need to remove this li as i am submitting a complete form with ajax that gets reset after submission. 我需要删除此li,因为我要提交带有ajax的完整表格,该表格在提交后会重置。 So the previous file name needs to be removed. 因此,需要删除先前的文件名。

Any help? 有什么帮助吗?

        <script type="text/javascript">

    var ID="";
    $(document).ready(function(e) {
         var uploader = new qq.FileUploader({
         element: document.getElementById('fine-uploader'),
         debug:true,
         action: '<?PHP echo base_url();?>index.php/teacher/addBook',
         allowedExtensions: ['jpeg', 'jpg', 'gif', 'png'],
         autoUpload:false,
         multiple:false,
                 template: '<div style="margin-left:0px !important; margin-top:10px" class="qq-uploader span3">' +
              '<pre class="qq-upload-drop-area span12"><span>{dragText}</span></pre>' +
              '<div class="qq-upload-button btn btn-success" style="width: auto;">{uploadButtonText}</div>' +
              '<ul class="qq-upload-list" style="margin-top: 10px; text-align: center; width:280px"></ul>' +
              '</div>',
        uploadButtonText: '<i class="icon-upload icon-white"></i> Upload Book Cover',
        onComplete:function(id,fileName,responseJSON){
            ID=responseJSON.id;
            },

        classes: {
            button: 'qq-upload-button',
            drop: 'qq-upload-drop-area',
            dropActive: 'qq-upload-drop-area-active',
            dropDisabled: 'qq-upload-drop-area-disabled',
            list: 'qq-upload-list',
            progressBar: 'qq-progress-bar',
            file: 'qq-upload-file',
            spinner: 'qq-upload-spinner',
            finished: 'qq-upload-finished',
            size: 'qq-upload-size',
            cancel: 'qq-upload-cancel',
            failText: 'qq-upload-failed-text',
            success: 'alert alert-success',
            fail: 'alert alert-error',
            successIcon: null,
            failIcon: null
        }

    });

    $("#add_book").click(function(){


            ready=true;
            if($("#name").val()=="")
            {
                $("#name").css('background-color','#FFF2F2').css('border-color','red'); ready=false;
            }

            if($("#author").val()=="")
            {
                $("#author").css('background-color','#FFF2F2').css('border-color','red'); ready=false;
            }

            if($("#isbn").val()=="")
            {
                $("#isbn").css('background-color','#FFF2F2').css('border-color','red'); ready=false;
            }

            if($("#subject").val()=="")
            {
                $("#subject").css('background-color','#FFF2F2').css('border-color','red'); ready=false;
            }
            if($("#ageGroup").val()=="")
            {
                $("#ageGroup").css('background-color','#FFF2F2').css('border-color','red'); ready=false;
            }
            if(ready)
            {
                uploader.setParams({name:$("#name").val(),author:$("#author").val(),isbn:$("#isbn").val(),subject:$("#subject").val(),age:$("#ageGroup").val()});
                uploader.uploadStoredFiles();
                $("#name").val("");
                $("#author").val("");
                $("#isbn").val("");
                $("#subject").val("");
                $("#ageGroup").val("")                      
            }


        });



    });
        </script>
            <div class="page">
           <div class="menu"><a href="#">Books</a> &nbsp;| &nbsp;<a href="#" class="active">Students</a></div>
                <h2>Add New Book</h2>
                                 <div class="send-form" id="book_form" >   

                          <p style="float:left">
                          <label>Book Title:</label>
                          <input class="u-3" name="name" id="name" />
                          </p>

                          <p style="float:right">
                          <label>Book Author</label>
                          <input class="u-3" name="author" id="author" />
                          </p>
                          <p style="float:left">
                          <label>Book ISBN</label>
                          <input class="u-3" name="isbn" id="isbn" />
                          </p>


                          <p style="float:right">
                          <label>Subject</label>
                          <input class="u-3" name="subject" id="subject" />
                          </p>

                           <p style="float:left">

                          <div id="fine-uploader" style="margin-left:0px !important">

                          </div>
                          </p> 
                          <p style="float:right; width:250px; margin-top:10px; margin-right:-10px">
                          <label>Age group (eg. 8-12)</label>
                          <input class="u-3" name="ageGroup" id="ageGroup" />

                          </p>

Fine Uploader 3.0 has a reset/dispose function. Fine Uploader 3.0具有重置/处置功能。 When I wrote it, I was not 100% sure how developers would use it, so it could possibly use some improvement, but it will, among other things, clear the list of uploaded files (if you are using FineUploader, as opposed to FineUploaderBasic). 当我写它的时候,我不是100%地确定开发人员将如何使用它,因此它可能会进行一些改进,但是它会清除上载的文件列表(如果您使用的是FineUploader,而不是FineUploaderBasic) )。

Note that 3.0 is scheduled to release in Nov. 19, but you can build the snapshot version now, if you'd like. 请注意,3.0计划于11月19日发布,但您可以根据需要立即构建快照版本。

You must include : 您必须包括:

 fnOnAdding: function(data)
    {   
      $('#fine-uploader').reset();
      return true;  
    },

But, in my case, with an editable datatable it resets the whole table while i was expecting to only reset the FileUploader related objects. 但是,就我而言,使用可编辑的数据表,它可以重置整个表,而我希望仅重置与FileUploader相关的对象。 Besides that it works. 除此之外,它的工作原理。

I don´t know if it is the same question but take a look at this topic: 我不知道这是否是相同的问题,但请看一下这个主题:

Delete Specific File From the List of Uploads 从上传列表中删除特定文件

Well, What I did is, in the fileuploader.js I´ve changed the filetemplate I´ve putted an ID to the <li> list, so In my HTML file ( in fact aspx) I wrote a Style for them 好吧,我所做的是,在fileuploader.js中,我已经更改了文件模板,并将ID放入了<li>列表,因此在我的HTML文件(实际上是aspx)中,我为它们编写了一个样式

in fileuploader.js locate 在fileuploader.js中找到

fileTemplate: '<li id="listaArquivos">' +
            '<span class="qq-upload-file"></span>' +
            '<span class="qq-upload-spinner"></span>' +
            '<span class="qq-upload-size"></span>' +
            '<a class="qq-upload-cancel" href="#">Cancel</a>' +
            '<span class="qq-upload-failed-text">Failed</span>' +
        '</li>'

<style>
      #listaArquivos
        {
            display: none;
        }
</style>

So that has vanished with the list. 因此,清单消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM