收藏
回答

课表这种嵌套数组怎么很好的for循环出来啊?看着头大,求大佬们给个思路

需求是做个类似于超级课程表那种格子,返回的数组如下,有什么好的思路嘛,弄得我头都大了😭

"schedule":[
[[{"place": "8-503", "name": "形势与政策", "time": "8:30 ~ 10:05", "color": "blue", "section": 2, "weeks_text": "8", "weeks_arr": [8], "teacher": "潘晶晶"}], [{"place": "8-501", "name": "思政课实践教学", "time": "10:25 ~ 12:00", "color": "purple", "section": 2, "weeks_text": "7,13", "weeks_arr": [7, 13], "teacher": "周红禄"}, {"place": "8-505", "name": "毛泽东思想和中国特色社会主义理论体系概论", "time": "10:25 ~ 12:00", "color": "purple", "section": 2, "weeks_text": "1-6,8-12,14-18", "weeks_arr": [1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18], "teacher": "周红禄"}], [{"place": "4-402", "name": "大学生职业发展与就业指导", "time": "14:40 ~ 16:15", "color": "red", "section": 2, "weeks_text": "1-4", "weeks_arr": [1, 2, 3, 4], "teacher": "朱玲梅"}], [], []],
[[], [{"place": "9-202", "name": "Android开发技术", "time": "10:25 ~ 12:00", "color": "green", "section": 2, "weeks_text": "1-19", "weeks_arr": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], "teacher": "段汝林"}], [], [], []],
[[{"place": "8-506", "name": "UI设计及应用", "time": "8:30 ~ 12:00", "color": "purple", "section": 4, "weeks_text": "1-19", "weeks_arr": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], "teacher": "陈萍"}], [], [{"place": "8-306", "name": "数据库应用技术", "time": "14:40 ~ 17:15", "color": "yellow", "section": 3, "weeks_text": "1-19", "weeks_arr": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], "teacher": "张晓健"}], [], []],
[[], [{"place": "9-202", "name": "Java Web开发技术", "time": "10:25 ~ 12:00", "color": "blue", "section": 2, "weeks_text": "1-19", "weeks_arr": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], "teacher": "段汝林"}], [{"place": "9-202", "name": "Android开发技术", "time": "14:40 ~ 16:15", "color": "purple", "section": 2, "weeks_text": "1-19", "weeks_arr": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], "teacher": "段汝林"}], [{"place": "8-503", "name": "形势与政策", "time": "16:30 ~ 18:05", "color": "red", "section": 2, "weeks_text": "10", "weeks_arr": [10], "teacher": "卓泽楼"}], []],
[[{"place": "9-202", "name": "Java Web开发技术", "time": "8:30 ~ 10:05", "color": "red", "section": 2, "weeks_text": "1-19", "weeks_arr": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], "teacher": "段汝林"}], [], [], [], []],
[[], [], [], [], []],
[[], [], [], [], []]
]
回答关注问题邀请回答
收藏

3 个回答

  • 耿霄
    耿霄
    2021-03-02

    建议对数据进行预处理,处理成模板想要的数据,这样模板只负责渲染,不要做复杂的逻辑判断

    2021-03-02
    有用 1
    回复 1
    • SARA
      SARA
      发表于移动端
      2021-03-02
      大佬说的对,其实这个数据结构说实话已经算完美了,就是我前段纵向渲染不好写,目前已经用猥琐的方法暂时实现了,打算有时间学个wxs,后期再更新
      2021-03-02
      回复
  • 朝阳
    朝阳
    2021-03-02

    可以看看我的小程序的实现,不过写的不是很好

    https://github.com/WindrunnerMax/SHST/blob/dev/SHST-UNI/pages/study/time-table/time-table.vue

    2021-03-02
    有用 1
    回复 2
    • SARA
      SARA
      发表于移动端
      2021-03-02
      感谢大佬,我会认真研究一下的,目前感觉最好的方案应该是wxs,但那玩意我不会整😭所以来这碰碰运气
      2021-03-02
      回复
    • 朝阳
      朝阳
      2021-03-02回复SARA
      我就是纯用的那个wxml解构写的,你可以看看第30行到44行就行,其实你用绝对定位也行,动态计算这个课表格子top和left
      2021-03-02
      回复
  • 银色子弹
    银色子弹
    2021-03-02

    问你同事

    2021-03-02
    有用
    回复 1
    • SARA
      SARA
      发表于移动端
      2021-03-02
      没有同事,单打独斗的,前后端都是我写😭
      2021-03-02
      回复
登录 后发表内容
问题标签