使用删除上传列表中的特定文件valums AJAX上传(Delete a specific file

2019-07-30 14:58发布

当上传使用AJAX valums上传文件,我们获得与文件名和文件大小的文件列表。 我想要的清单来与文件名,文件大小和删除链接的文件。 这样当上删除该文件的用户点击应该得到所显示的列表中。 我是成功的在得到每个文件的删除链接,但我有较少的JavaScript知识是无法处理,因为我想要的。 如果有人能帮助将是巨大的。 这就是我现在uptil做。

 function deleteme(id){
 //something like this
     var item = this._getItemByFileId(id);                
     qq.remove(this._find(item));
 }     

fileTemplate:'<li>' +
            '<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>' +
            '<a class="qq-upload-del-text" href="javascript:deleteme(this.id);">Delete</a>' +
            '</li>',

提前致谢。

Answer 1:

我用的是FileUploaderBasic版本以及所面临的同样的问题。 所以,我做了一个DIY删除

下面是完整的例子:

var $fub = $('#fine-uploader-basic'),
                                    $messages = $('#upload-messages');

                                // try the basic uploader 

                                var uploader = new qq.FileUploaderBasic({
                                        button: $fub[0],
                                        action: base_ajax_url + 'upload',
                                        debug: true,
                                        autoUpload: false,
                                        allowedExtensions: ['jpeg', 'jpg', 'gif', 'png'],
                                        sizeLimit: 204800, // 200 kB = 200 * 1024 bytes
                                        // the method name really should be onSelect 
                                        onSubmit: function(id, fileName) {

                                            var _self = this;

                                            var entry = $('<div id="file-' + id + '" class="alert" style="margin: 10px 0 0">' + fileName + ' <span class="qq-upload-cancel close">&times;</span></div>'
                                                ).appendTo(
                                                    $messages[0]
                                                ).find('.qq-upload-cancel').click(function() {
                                                    _self._storedFileIds.splice(_self._storedFileIds.indexOf(id) , 1);
                                                    $($(this).parent()).remove();
                                                return false;
                                                });

                                        },
                                        onUpload: function(id, fileName) {
                                            $('#file-' + id).addClass('alert-info')
                                                .html('<img src="/sites/all/themes/pb_admin/images/loading.gif" alt="Initializing. Please hold."> ' +
                                                'Initializing ' +
                                                '"' + fileName + '"');
                                        },
                                        onProgress: function(id, fileName, loaded, total) {
                                            if (loaded < total) {
                                              progress = Math.round(loaded / total * 100) + '% of ' + Math.round(total / 1024) + ' kB';
                                              $('#file-' + id).removeClass('alert-info')
                                                              .html('<img src="/sites/all/themes/pb_admin/images/loader.gif" alt="In progress. Please hold."> ' +
                                                                    'Uploading ' +
                                                                    '"' + fileName + '" ' +
                                                                    progress);
                                            } else {
                                              $('#file-' + id).addClass('alert-info')
                                                              .html('<img src="/sites/all/themes/pb_admin/images/loader.gif" alt="Saving. Please hold."> ' +
                                                                    'Saving ' +
                                                                    '"' + fileName + '"');
                                            }
                                        },
                                        onComplete: function(id, fileName, responseJSON) {
                                            if (responseJSON.success) {
                                              $('#file-' + id).removeClass('alert-info')
                                                              .addClass('alert-success')
                                                              .html('<i class="icon-ok"></i> ' +
                                                                    'Successfully saved ' +
                                                                    '"' + fileName + '"');
                                            } else {
                                              $('#file-' + id).removeClass('alert-info')
                                                              .addClass('alert-error')
                                                              .html('<i class="icon-exclamation-sign"></i> ' +
                                                                    'Error with ' +
                                                                    '"' + fileName + '": ' +
                                                                    responseJSON.error);
                                            }
                                        }
                                     });

(这个名字的onsubmit有点可疑......反正)

我试着拨打onCancel方法(但抛出异常是不确定的)。

然后这一个工程-从_storedFileIds阵列删除ID。 仅此而已。



文章来源: Delete a specific file from the list of uploads using valums ajax uploader