weixin_33695082 2015-11-23 19:04 采纳率: 0%
浏览 39

通过ajax加载图像数组

so I have an array as response when i upload images with dropzone:

{50: "/media/50/twitter cover photos for new year 2016.png", 51: "/media/51/174920-1280.png",…}

50: "/media/50/twitter cover photos for new year 2016.png"
51: "/media/51/174920-1280.png"
52: "/media/52/buy-instagram-followers.jpg"

Now i want to append this:

 <div class="col-lg-2 col-md-4 col-xs-6 thumb">
       <img class="img-responsive" src=" // the values of the response array //" alt="">
       <div class="galleryremovebutton">
          <a href="/delete/ the keys / ids of the response array " class="btn btn-danger" role="button">Izbrisi sliku</a>
       </div>
 </div>

as a loop to this:

<div id="galleryimgs" class="row">

After the complete event of dropzone, that means i would need this code here somewhere:

Dropzone.options.myGalleryDropzone = {

            paramName: "file", // The name that will be used to transfer the file
            maxFilesize: 1, // MB
            parallelUploads: 8,
            complete: function () {
                HERE
            }
        };
  • 写回答

1条回答 默认 最新

  • weixin_33734785 2015-11-23 19:22
    关注

    Using only jQuery, you have a choice between building the DOM through a string or programmatically. Either way, it should be a DOM element wrapped in jQuery:

    function makeThumb() {
      // $('html_for_one_thumbnail');
      // $('<div />').append('<div />')...etc;
      return elementForThumb;
    }
    

    Then another function to populate the element:

    function configureThumb($element, thumb, thumbId) {
      $element.find('img').attr('src', thumb);
      $element.find('a').attr('href', '/delete/' + thumbId);
    }
    

    And one more to put it together:

    function buildThumbnails($element, thumbs) {
      thumbs.forEach(function(thumb, thumbId) {
        var $thumb = makeThumb();
        $element.append($thumb);
        configureThumb($thumb, thumb, thumbId);
      });
    }
    

    Called at the complete, assuming the container is empty:

    complete: function(data) {
        buildThumbnails($('#galleryimgs'), data);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵