开发者

how to append multiple values to a list + jQuery

开发者 https://www.devze.com 2023-04-04 09:33 出处:网络
Following shows how to manually set each href to the image path and set the class. $.fancybox([{ \'href\': \'/image/1.jpg\',

Following shows how to manually set each href to the image path and set the class.

$.fancybox([{
                            'href'  : '/image/1.jpg',
                            'class' : 'iframe'
                        },
                        {
                            'href'  : '/image/2.jpg',
                            'class' : 'iframe'
                        },
                        {
                            'href'  : '/image?blob_key={{ path }}',
                            'class' : 'iframe'
                        }
                    ], {
                        'padding'           : 0,

If I have a loop, how to append the value of those "href" and "class" that are enclosed with 开发者_如何学JAVAcurly bracket as shown above to a list in jQuery?

EDIT

{% for photo in photos %}
// how to add this  "/image?blob_key={{ photo.photo_blobstore_key }} to the $.fancybox ?

{% endfor %}

Question Closed:

Solved with:

 var options = [];
            {% for photo in photos %}
                options.push({
                    'href'  : 'image?blob_key={{ photo.photo_blobstore_key }}',
                    'class' : 'iframe'
                });

Sorry. I wasn't familiar with jQuery and thus asked this simple question. Question Closed as it has been resolved.


I'm assuming you're trying to add multiple images inside some container div... Correct?

$.each(photos, function(i,e){
    $("#fancybox").append($("<img src='"+ e.href +"' class='"+ e.class +"'/>"));
 });


var options = [];
   {% for photo in photos %}
      options.push({
          'href'  : 'image?blob_key={{ photo.photo_blobstore_key }}',
          'class' : 'iframe'
      });
   {% endfor %}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号