如何在dropzone插件

时间:2016-04-23 07:55:06

标签: jquery dropzone.js

我正在使用dropzone插件。当在更新模式下加载现有文件时,我在init事件时需要id属性。

提前致谢

1 个答案:

答案 0 :(得分:0)

init:function(){                 var myDropzone = this;                 $( '#div_breakfast_img_org_name')追加()。                 $( '#div_breakfast_img_file_name')追加()。                 $( '#breakfast_sequence')VAL( '');

            if ('<?php echo count($bfImageArrayData) ?>')
            {
                    <?php foreach ($bfImageArrayData as $bfImage) { ?>
                    var mockFile = {name: '<?php echo $bfImage['image_name']; ?>', sfn: '<?php echo base64_encode('/diet_image/' . $bfImage['image']); ?>', };
                    var thumbUrl = '<?php echo url('/'); ?>/uploads/diet_image/<?php echo $bfImage['image']; ?>';
                                        // Call the default addedfile event handler
                                        myDropzone.emit("addedfile", mockFile);
                                        // And optionally show the thumbnail of the file:
                                        myDropzone.emit("thumbnail", mockFile, thumbUrl);
                                        //myDropZone.uploadProgress(100);
                                        myDropzone.files.push(mockFile);
                                        $(mockFile.previewElement).prop('id', '<?php echo $bfImage['image']; ?>');
                                        $('.dz-progress').remove();
                                        //i++;
                    <?php } ?>
            }
                                // removed file event 
            myDropzone.on('removedfile', function (file) {
                var sfnValue = file.sfn;
                var filePath = '';
                $.each($(file.xhr), function (key, val) {
                    filePath = $.parseJSON(val['response']).newFilename;
                });
                var fileName = file.name;
                // To get file path value 
                var s = 0;
                var filePathArray = new Array();
                $('input[name^="breakfast_img_file_name"]').each(function () {//alert($(this).val());
                    filePathArray[s] = $(this).val();
                    s++;
                });

                // To get file original Name 
                var t = 0;
                var fileNameArray = new Array();
                $('input[name^="breakfast_img_ori_name"]').each(function () {//alert($(this).val());
                    fileNameArray[t] = $(this).val();
                    t++;
                });

                $.ajax({
                    url: '/upload/remove-diet-image',
                    data: {sfn: file.sfn, id: '<?php echo $diet_subcategory_id_pk; ?>', type: 'diet-image', fileName: fileName, filePath: filePath, fileNameArray: fileNameArray, filePathArray: filePathArray, action: 'breakfast'},
                }).done(function (result) {//console.log(result.filename);
                    result = $.parseJSON(result);
                    $('#div_breakfast_img_org_name').remove();
                    $('#div_breakfast_img_file_name').remove();
                    $('.box-footer').append('<div id="div_breakfast_img_org_name">' + result.filename + '</div>');
                    $('.box-footer').append('<div id="div_breakfast_img_file_name">' + result.filepath + '</div>');
                });
            });
        },