Rails、二维表、枢轴、嵌套哈希循环
我正在构建成绩册报告 - 一个二维表格,水平显示课程名称,垂直显示学生列表。
Student Name | LessonID x | LessonID x | LessonID x
Joe 95% 95%
Mary 80% 80%
Sam 80% 80%
我的数据位于包含以下字段的表中:
student_id, lesson_id, grade_in_pct, grade_in_pts, grade_high, grade_low, grade_median
学生和课程的总数不固定。
我考虑过使用 ruport/acts_as_reportable 或 mysql 数据透视程序,但看起来数据透视表只给了我一维。所以这是行不通的,因为在我看来,我想添加鼠标悬停功能和条件格式以显示每个成绩的更多信息。
所以我认为我唯一的选择是生成一个嵌套哈希,然后在视图中循环它。你有什么想法?有人可以建议一种构建嵌套哈希的方法吗?循环遍历 250 行(约 50 名学生,每人 5 节课)是否会导致处理器过于密集?
我被困住了。请帮忙。谢谢!
I am building grade-book report - a two dimensional table that shows lesson names going horizontally and a list of students going vertically.
Student Name | LessonID x | LessonID x | LessonID x
Joe 95% 95%
Mary 80% 80%
Sam 80% 80%
My data is in a table that has these fields:
student_id, lesson_id, grade_in_pct, grade_in_pts, grade_high, grade_low, grade_median
The total number of students and lessons is not fixed.
I considered using ruport/acts_as_reportable or mysql pivot procedure, however it looks like the pivot only gives me one dimension. So that's not going to work, because in my view I want to add mouse-over features and conditional formatting to show more info on each grade.
So I think my only option is to generate a nested hash and then loop through it in the view. What are your thoughts? Could someone suggest a way to build a nested hash? Would it be too processor intensive to loop through 250 rows (~50 students, 5 lessons each)?
I am stuck. Please help. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我就是这样做的:
This is how I would do it: