微信小程序 for循环嵌套怎么取值

 

外层循环正常嵌套,内层循环嵌套的时候,把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: "有效期内可以享受日常课"
      },
    ]
  }

  参考:https://blog.csdn.net/weixin_38930535/article/details/79152627

  参考:https://www.cnblogs.com/handsomeBoys/p/6599062.html

转载于:https://www.cnblogs.com/jvziking/p/9451294.html

你可能感兴趣的:(微信小程序 for循环嵌套怎么取值)