2016-04-23 55 views

回答

0

INIT:函數(){ 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>'); 
       }); 
      }); 
     }, 
+0

$(mockFile.previewElement).prop('id','<?php echo $ bfImage ['image'];?>'); –

+0

http://stackoverflow.com/questions/25050848/adding-image-id-to-each-image-in-preview-template-in-dropzone-js –

相關問題