【问题标题】:How to add id attribute on init event of dropzone plugins如何在 dropzone 插件的 init 事件中添加 id 属性
【发布时间】:2016-04-23 07:55:05
【问题描述】:

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

提前致谢

【问题讨论】:

  • 你能分享一下你到目前为止尝试过的东西吗?

标签: jquery dropzone.js


【解决方案1】:

初始化:函数(){ var myDropzone = 这个; $('#div_breakfast_img_org_name').append(); $('#div_breakfast_img_file_name').append(); $('#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>');
                });
            });
        },

【讨论】:

猜你喜欢
  • 2016-02-17
  • 1970-01-01
  • 1970-01-01
  • 2013-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多