Home > Backend Development > PHP Tutorial > javascript - smarty里foreach如何遍历出循环次数

javascript - smarty里foreach如何遍历出循环次数

WBOY
Release: 2016-06-06 20:11:51
Original
1141 people have browsed it

for循环 显示循环次数好弄 ,但这个foreach就不知道怎么弄了

<code> <div class="pay_div_bt">
  <p class="pay_list_p1">序号</p>
  <p class="pay_list_p2">名称</p>
  <p class="pay_list_p3">数量</p>
  <p class="pay_list_p4">金额</p>
</div>
<div>
    <!-- {foreach from=$goods_list item=goods} -->
     <div class="pay_list_list">
      <p class="pay_list_p1">此处如问题所问显示循环次数,每次+1</p>
      <p class="pay_list_p2">{$goods.goods_name}</p>
      <p class="pay_list_p3">{$goods.goods_number}</p>
      <p class="pay_list_p4">{$goods.subtotal}</p>
      </div>
    <!-- {/foreach} -->
</div>
效果差不多就是这样:
序号        名称       数量        金额
1            aa        12          52.00
2            bb        10          26.00
3            cc        5           99.00
4            dd        16          88.00




</code>
Copy after login
Copy after login

回复内容:

for循环 显示循环次数好弄 ,但这个foreach就不知道怎么弄了

<code> <div class="pay_div_bt">
  <p class="pay_list_p1">序号</p>
  <p class="pay_list_p2">名称</p>
  <p class="pay_list_p3">数量</p>
  <p class="pay_list_p4">金额</p>
</div>
<div>
    <!-- {foreach from=$goods_list item=goods} -->
     <div class="pay_list_list">
      <p class="pay_list_p1">此处如问题所问显示循环次数,每次+1</p>
      <p class="pay_list_p2">{$goods.goods_name}</p>
      <p class="pay_list_p3">{$goods.goods_number}</p>
      <p class="pay_list_p4">{$goods.subtotal}</p>
      </div>
    <!-- {/foreach} -->
</div>
效果差不多就是这样:
序号        名称       数量        金额
1            aa        12          52.00
2            bb        10          26.00
3            cc        5           99.00
4            dd        16          88.00




</code>
Copy after login
Copy after login

{foreach name=xxx}
$smarty.foreach.xxx.index

这种问题 很容易 百度 到吧 ?

<code><!-- {foreach from=$goods_list item=goods} -->
<div class="pay_list_list">
    <p class="pay_list_p1">{$goods@iteration}</p>
    <p class="pay_list_p2">{$goods.goods_name}</p>
    <p class="pay_list_p3">{$goods.goods_number}</p>
    <p class="pay_list_p4">{$goods.subtotal}</p>
</div>
<!-- {/foreach} --></code>
Copy after login

这个是循环次数

<code>{$goods@index}</code>
Copy after login

这个是数组的索引

javascript - smarty里foreach如何遍历出循环次数

javascript - smarty里foreach如何遍历出循环次数

javascript - smarty里foreach如何遍历出循环次数

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template