微信小程序wx:for 根据 index 换行问题

末子
  • 63
<view class='exh-list'>
   <view class='row'>
      <view class='item' bindtap='showService' data-index='5'>
         <image src='../../public/images/ad01.jpg' mode='widthFix' class='head-img'></image>
         <text>rs0001</text>
      </view>
      <view class='item' bindtap='showService' data-index='6'>
         <image src='../../public/images/ad01.jpg' mode='widthFix' class='head-img'></image>
         <text>rs0002</text>
      </view>
      <view class='item' bindtap='showService' data-index='7'>
         <image src='../../public/images/ad01.jpg' mode='widthFix' class='head-img'></image>
         <text>rs0003</text>
      </view>
   </view>
   <view class='row'>
      <view class='item' bindtap='showService' data-index='8'>
         <image src='../../public/images/ad01.jpg' mode='widthFix' class='head-img'></image>
         <text>rs0004</text>
      </view>
      <view class='item' bindtap='showService' data-index='9'>
         <image src='../../public/images/ad01.jpg' mode='widthFix' class='head-img'></image>
         <text>rs0005</text>
      </view>
      <view class='item' bindtap='showService' data-index='10'>
         <image src='../../public/images/ad01.jpg' mode='widthFix' class='head-img'></image>
         <text>rs0006</text>
      </view>
   </view>
</view>

形如上方代码,如何循环 ?

回复
阅读 2.9k
1 个回答

我是用两层循环做的

<view class='exh-list'>
    <block wx:for="{{2}}" wx:for-index="i" wx:for-item="item_i" wx:for-key="key_i">
        <view class='row'>
            <block wx:for="{{3}}" wx:for-index="j" wx:for-item="item_j" wx:for-key="key_j">
                <view class='item' bindtap='showService' data-index='{{i*3+j+5}}'>
                     <image src='../../public/images/ad01.jpg' mode='widthFix' class='head-img'></image> 
                    <text>rs000{{i*3+j+1}}</text>
                </view>
            </block>
        </view>
    </block>
</view>

结果

结果

宣传栏