2

我正在使用jquery-fileupload-railsGem 在我的应用程序中上传图像。这是代码:

<script id="template-upload" type="text/x-tmpl">
  <div class="upload ">
  {%=o.name%}
  <div class="progress"><div class="bar" style="width: 0%"></div></div>

<div class="photo-post-img">
<%= form_for Upload.new do |f| %>
  <span class="btn btn-primary fileinput-button ml30">
    <b>+</b>
    <span class="text-orange">Add image</span>
    <%= f.file_field :upload, multiple: true, name: "upload[upload]" %>
    <%= f.hidden_field :post_id, :value => @post.upload_id %>
    <%= f.hidden_field :upload_type, :value => @post.upload_type %>
  </span>
<% end %>
<div class="img-upload-list">
  <ul id="photos_uploaded" class="thumbnails pull-left">
    <% @post.uploads.each do |upload| %>
      <li class="thumbnail" id="uploads-<%=upload.id %>">
        <%=image_tag upload.upload.url(:medium) %>
        <%= link_to "Delete", upload, :remote => true, :method => "delete" %>
      </li>
     <% end %>
  </ul>
</div>

在 .js 文件中:

jQuery(function() {
  return $('#new_upload').fileupload({
  dataType: "script",
  add: function(e, data) {
    var file, types;
    types = /(\.|\/)(gif|jpe?g|png)$/i;
    file = data.files[0];
    if (types.test(file.type) || types.test(file.name)) {
      data.context = $(tmpl("template-upload", file));
      $('#new_upload').append(data.context);
      return data.submit();
    } else {
       return alert("" + file.name + " is not a gif, jpeg, or png image file");
    }
   },

   progress: function(e, data) {
     var progress;
     if (data.context) {
       progress = parseInt(data.loaded / data.total * 100, 10);
       return data.context.find('.bar').css('width', progress + '%');
      }
    },
   done: function (e, data) {
     $('.upload').attr('style', 'visibility: hidden');
   }
 });
});

一切正常,但图像上传后,进度条不会删除。上传后如何删除栏?

4

1 回答 1

4

而不是回调在你的 js 文件中 done添加回调stop

stop: function (e, data) {
  $('.upload').hide();
},
于 2013-06-06T05:10:21.587 回答