2011-09-13 34 views
0

以下显示了如何手动将每个href设置为图像路径并设置类。如何将多个值附加到列表中+ jQuery

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

如果我有一个环,如何那些附加的“href”和“类别”被包围的花括号如上所示在jQuery的列表的值?

编辑

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

{% endfor %} 

问题已关闭:

解决了:

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

对不起。我不熟悉jQuery,因此问了这个简单的问题。问题已解决,因此已关闭。

+0

你已经有循环加载页面时,或者是你动态地添加元素到您的网页? –

+0

请将您的解决方案发布为***答案***,然后,如果可以,请接受该答案。否则系统会认为这个问题没有答案(或者至少是'未解决')。 –

+0

感谢大卫的建议。 :) – MrCooL

回答

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

我假设你试图在一些容器div中添加多个图像...正确吗?

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