在开发微信小程序中遇到循环嵌套怎么取值以下是解决办法:

外层循环正常嵌套,内层循环嵌套的时候,把item.swiper_buy作为数组循环wx:for="{{item.swiper_buy}}",然后给item重新命名wx:for-item="cell",内部循环的时候,就是{{cell.属性}}

wxml:

<block wx:for="{{swiper_object}}" wx:key="index">
    <swiper-item>
      <view class='swiper_in'>
        <view class='head_img'>
          <image src="{{item.head_img}}"></image>
          <view class='head_in'>
            <view class='card_name'>嘻哈帮街舞.{{item.card_name}}</view>
            <view class="card_i">{{item.card_use}}</view>
            <view class='use_region'>{{item.card_region}}</view>
          </view>
        </view>
        <view class='buy_list'>
          <block wx:for="{{item.swiper_buy}}" wx:for-item="cell" wx:key="index">
            <view class="buy_item {{num==index?'current':''}}"   data-index="{{index}}" catchtap='switchTab'>
              <view class='buy_price'>
                <view class='card_price'>¥{{cell.buy_price}}</view>
                <view class='nk_species'>{{cell.card_species}}</view>
              </view>
              <view class='buy_zs'>{{cell.buy_send}}</view>
            </view>
          </block>
        </view>
      </view>
    </swiper-item>
    </block>
js:

data: {
    num: 0,
    swiper_object:[
      {
        swiper_buy: [
          {
            buy_price: "1100",
            card_species: "年卡D",
            buy_send: "购买1课点"
          },
          {
            buy_price: "2200",
            card_species: "年卡C",
            buy_send: "购买9课点"
          },
          {
            buy_price: "3300",
            card_species: "年卡B",
            buy_send: "购买3课点"
          }
        ],
        head_img:"../../images/head_img1.png",
        card_name:"次卡",
        card_use:"49/课点",
        card_region:"本课点全国通用"
      },
      {
        swiper_buy: [
          {
            buy_price: "1400",
            card_species: "一年通",
            buy_send: "有效期内享受日课程课"
          },
          {
            buy_price: "2500",
            card_species: "两年通",
            buy_send: "有效期内享受日课程课"
          },
          {
            buy_price: "46000",
            card_species: "单店通",
            buy_send: "赠本企业续存期内"
          }
        ],
        head_img: "../../images/head_img2.png",
        card_name: "少儿畅舞卡",
        card_use: "本地使用",
        card_region: "有效期内可以享受日常课"
      },
    ]
  }

以上是此次遇到问题的解决办法

点赞(0) 打赏

Comment list 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部