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

小程序 文章 2021-03-02 19:41 315 0 全屏看文

AI助手支持GPT4.0

课表这种嵌套数组怎么很好的for循环出来啊?看着头大,求大佬们给个思路How can such a nested array of class schedule come out in a good for loop? Seeing that the head is big, ask the big guys for ideas

课表这种嵌套数组怎么很好的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": "段汝林"}], [], [], [], []],[[], [], [], [], []],[[], [], [], [], []]]

The requirement is to make a grid similar to the super curriculum schedule. The returned array is as follows. What's a good idea? It makes my head big 😭 "Schedule": [[[{"place": "8-503", "name": "situation and policy", "time": "8:30 ~ 10:05", "color": "blue", "section": 2, "weeks"_ text": "8", "weeks_ Arr ": [8]," teacher ":" Pan Jingjing "}], [{" place ":" 8-501 "," name ":" Ideological and political practice teaching "," time ":" 10:25 ~ 12:00 "," color ":" purple "," section ": 2," weeks "_ text": "7,13", "weeks_ [7,13], "teacher": "Zhou Honglu"}, {"place": "8-505", "name": "Introduction to Mao Zedong Thought and theoretical system of socialism with Chinese characteristics", "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 ":" Zhou Honglu "}], [{place": "4-402", "name": "career development and employment guidance for college students", "time": "14:40 ~ 16:15", "color": "red", "section": 2, "weeks"_ text": "1-4", "weeks_ Arr ": [1, 2, 3, 4]," teacher ":" Zhu Lingmei "}], [], [], [], [{" place ":" 9-202 "," name ":" Android development technology "," 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 ":" Duan Rulin "}], [], [], []], [{" place ":" 8-506 "," name ":" UI design and application "," 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 ":" Chen Ping "}], [], [{place": "8-306", "name": "database application technology", "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 ":" Zhang Xiaojian "}], [], [], [], [{place": "9-202", "name": "java web development technology", "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 ":" Duan Rulin "}], [{place": "9-202", "name": "Android development technology", "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 ":" Duan Rulin "}], [{place": "8-503", "name": "situation and policy", "time": "16:30 ~ 18:05", "color": "red", "section": 2, "weeks"_ text": "10", "weeks_ Arr ": [10]," teacher ":" zhuozhelou "}], []], [{" place ":" 9-202 "," name ":" java web development technology "," 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 ":" Duan Rulin "}], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]

回答:

朝阳:

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

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

零樱:感谢大佬,我会认真研究一下的,目前感觉最好的方案应该是wxs,但那玩意我不会整😭所以来这碰碰运气
|G.XIAO|:

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

银色子弹:

问你同事

零樱:没有同事,单打独斗的,前后端都是我写😭

-EOF-

AI助手支持GPT4.0