小程序页面渲染二维数组

  <view class="card">
    <view wx:for="{
   
   {nowChess}}" wx:key-item="item" wx:for-index="indexs" wx:key="indexs" class="child">
      <view wx:for="{
   
   {item}}" wx:key-item="item" wx:key="index" class="children">
        <view class="button{
   
   {item}}" bindtap="clickButton" data-indexs="{
   
   {indexs}}" data-index="{
   
   {index}}">
          {
   
   {indexs}},{
   
   {index}}
        </view>
      </view>
    </view>
  </view>

HTML

    for (var i = 0; i < 8; i++) {
      for (var j = 0; j < 8; j++) {
        this.setData({
          ["nowChess[" + i + "][" + j + "]"]: 0,
          ["nowChess[" + 3 + "][" + 3 + "]"]: 2,
          ["nowChess[" + 4 + "][" + 3 + "]"]: 1,
          ["nowChess[" + 3 + "][" + 4 + "]"]: 1,
          ["nowChess[" + 4 + "][" + 4 + "]"]: 2,
        })
      }
    };

初始化二维数组,JS

猜你喜欢

转载自blog.csdn.net/weixin_51263829/article/details/129087430