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 docker无法进入容器内部
    • ¥15 qt https 依赖openssl 静态库
    • ¥15 python flask 报错
    • ¥15 改个密码引发的项目启动问题
    • ¥100 CentOS7单线多拨
    • ¥15 debian安装过程中老是出现无法将g21dr复制到g21dr怎么解决呀?
    • ¥15 如何用python实现跨工作簿的指定区域批量复制粘贴
    • ¥15 基于CH573f的雷迪安CR1400m通讯代码
    • ¥15 matlab m文件如何与matla app designer 数据交互?
    • ¥15 根据控制框图,传递函数求解