开发者

how to append multiple values to a list + jQuery

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜