首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > PHP >

smarty模板中,js中如何嵌套foreach或section循环

2013-09-05 
smarty模板中,js中怎么嵌套foreach或section循环?这是静态页。scriptvar box new PPTBox()box.width

smarty模板中,js中怎么嵌套foreach或section循环?
这是静态页。


          <script>
                                     var box =new PPTBox();
                                     box.width = 1250; //宽度
                                     box.height = 490;//高度
                                     box.autoplayer = 3;//自动播放间隔时间
                                     //box.add({"url":"图片地址","title":"悬浮标题","href":"链接地址"})
                                     box.add({"url":"images/tu1.jpg","title":"悬浮提示标题1"});
                                     box.add({"url":"images/tu2.jpg","title":"悬浮提示标题2"});
                                     box.add({"url":"images/tu3.jpg","title":"悬浮提示标题3"});
                                     box.add({"url":"images/tu4.jpg","title":"悬浮提示标题4"});
                                     box.show();
                                </script>




用smarty循环,实现这样

{literal}
                                 <script>
                                     var box =new PPTBox();
                                     box.width = 1250; //宽度
                                     box.height = 490;//高度
                                     box.autoplayer = 3;//自动播放间隔时间
                                     //box.add({"url":"图片地址","title":"悬浮标题","href":"链接地址"})
{foreach item=lop from=$tuan }
        box.add({"url":"./upload/admin/{$lop.image}","title":"{$lop.title}"});
{/foreach}
        box.show();
                                </script>


[解决办法]
for(var i=0; i<obj.length; i++)
  {
      box.add({"url":'"'+obj[i].url+'"',"title":'"'+obj[i].title+'"'});
  }

热点排行