微信小程序之view动态布局

wxml

<view class='main'>
   <view wx:for="{{long}}" wx:key="*this" class='items'>
       <view class='il'>{{item[0].acmonth}}</view>
       <view class='ir' wx:if="{{item[1]!=undefined}}">{{item[1].acmonth}}</view>
   </view>
</view>

wxss

page{width: 100%;height: 100%;}
.main{display: flex;flex-direction: column;}
.items{display: flex;}
.il{width: 40%;height: 80px; text-align: center;border: 1px solid #000;margin: 5%;box-sizing: border-box;}
.ir{width: 40%;height: 80px; text-align: center;border: 1px solid #000;margin: 5%;box-sizing: border-box;}

js

Page({
  data: {
    active: [{
      "acmonth": 1,
      "actype": "游泳"
    },
    {
        "acmonth": 4,
        "actype": "游泳"
      },
    {
        "acmonth": 8,
        "actype": "游泳"
      },
    {
        "acmonth": 1,
        "actype": "游泳"
      },
    {
        "acmonth": 6,
        "actype": "游泳"
      },
    {
        "acmonth": 7,
        "actype": "游泳"
      },
    {
        "acmonth": 3,
        "actype": "游泳"
      },
    {
        "acmonth": 8,
        "actype": "游泳"
      },
    {
        "acmonth": 11,
        "actype": "游泳"
      },
    {
        "acmonth": 1,
        "actype": "游泳"
      },
    {
        "acmonth": 12,
        "actype": "游泳"
      },
    {
        "acmonth": 9,
        "actype": "游泳"
      },
    {
        "acmonth": 5,
        "actype": "游泳"
      },
    {
        "acmonth": 2,
        "actype": "游泳"
      },
    {
        "acmonth": 6,
        "actype": "游泳"
      }],
      long:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      console.log(this.data.active)
      var total=this.data.active
      var xin=[]
      for(var i=0;i<total.length;i++){
        for(var j=0;j<total.length/2;j++){
          if (i / 2 == j){
            console.log(i)
            xin[j]=[total[i],total[i+1]]
          }
        }
      }
      this.setData({
         long:xin
      })
    console.log(this.data.long[7][1]==undefined)
  }
})

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值