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

<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>

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

阅读 4.4k
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>

结果

结果

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题