我的 Fine Uploader 实现——使用核心模式和 jQuery——工作正常,直到我尝试上传第二批文件。
当第一批文件上传(成功)后,我可以单击按钮添加文件并获得选择文件的对话框。但是,在我确认文件选择后,什么也没有发生。
处理程序中的这段代码complete
导致了问题:
$('#attachments-upload').button('reset'); // Bootstrap stateful button
#attachments-upload
也是设置为button:
选项的按钮的 ID。这是完整的 JS 代码清单:
$('#attachments-list').fineUploader({
uploaderType: 'basic',
button: $('#attachments-upload'),
debug: true,
request: {
endpoint: $route_atatachments_upload,
inputName: 'attachments'
},
validation: {
allowedExtensions: ['png', 'jpeg', 'gif', 'pdf', 'doc', 'bmp'],
sizeLimit: 10485760 // 10MB
}
})
.on('upload', function(event, id, fileName) {
$('#attachments-upload-error').hide();
$('#attachments-upload').button('loading');
$('#attachments-upload-progress').show().attr('aria-valuenow', 0);
})
.on('progress', function(event, id, fileName, loaded, total) {
if (loaded < total) {
var progress = Math.round(loaded / total * 100) + '% of ' + Math.round(total / 1024) + ' kB';
$('#attachments-upload-progress').attr('aria-valuenow', progress);
} else {
$('#attachments-upload-progress').attr('aria-valuenow', 100);
}
})
.on('complete', function(event, id, fileName, responseJSON) {
$('#attachments-upload-progress').hide();
$('#attachments-upload').button('reset');
if (responseJSON.success) {
$('<tr class="attachment" data-attachment-uuid="'+ responseJSON.uuid + '">' +
'<td>' + fileName +'</td>' +
'<td>' + humanFileSize(responseJSON.size) + '</td>' +
'<td style="text-align: center"><a class="delete-attachment" href="#"><span class="glyphicon glyphicon-trash" </a></td>' +
'</tr>').
insertBefore($('#add-attachment'));
} else {
$('#attachments-upload-error').show();
console.log(responseJSON.error);
}
});
这是 HTML:
<table class="table table-bordered" id="attachments-list">
<thead>
<tr>
<th>Name</th>
<th>Size</th>
<th></th>
</tr>
</thead>
<tbody id="added-attachments">
<tr id="add-attachment">
<td colspan="2">
<div id="attachments-upload-progress" class="progress progress-striped active" style="display:none">
<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</td><td style="width:1%; white-space:nowrap;">
<button id="attachments-upload" class="btn btn-success" data-loading-text="loading ..." style="position: relative; overflow: hidden; direction: ltr; ">Add Files ...</button>
</td>
</tr>
</tbody>
</table>
但正如我所说,如果我评论以下行,
$('#attachments-upload').button('reset');
一切正常。