×

微信小程序:获取两层(多层)数组最里层的length

作者:andy0012019.03.05来源:Web前端之家浏览:21403评论:0
关键词:小程序length

想要获得TtimeList的总个数,数据如下:

teacherList: [
      {
        Tname: 'aaaaaa',
        Ttime: 'aaaaaaaaaaaaa',
        TtimeList: [
          {
            Ltime: 'aaaaaaaaaaaaaaaaa',
            Lunit: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa'
          }
        ]
      },
      {
        Tname: 'bbbbbb',
        Ttime: 'bbbbbbbbbbbbbbbbbbb',
        TtimeList: [
          {
            Ltime: 'bbbbbbbbbbbbbbbb',
            Lunit: 'bbbbbbbbbbbbbbbbbbbbbbbbbb'
          },
          {
            Ltime: 'bbbbbbbb',
            Lunit: 'bbbbbbbbbbbbbb'
          },
        ]
      }, {
        Tname: 'cccc',
        Ttime: 'ccccccccccc',
        TtimeList: [
          {
            Ltime: 'ccccccccccccccccc',
            Lunit: 'ccccccccccccccccccccccccc'
          },
          {
            Ltime: 'ccccccccc',
            Lunit: 'cccccccccccccccccccccccccccccccccc'
          },
        ]
      }
    ],
    courseOutline: 0,

JS如下:

var len2 = 0;
    for (var L1 = 0; L1 < this.data.teacherList.length; L1++) {
      var newArr = this.data.teacherList[L1].TtimeList;
      for (var L2 = 0; L2 < newArr.length; L2++) {
       // console.log(newArr[L2]);
        len2++;
      }
    }
    // console.log(len2);
    this.setData({
      courseOutline: len2
    })

wxml如下:

 <view>{{courseOutline}}次课</view>

您的支持是我们创作的动力!
温馨提示:本文作者系 ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://jiangweishan.com/article/html283402380fspdif.html

网友评论文明上网理性发言 已有0人参与

发表评论: