使用Jade npm显示mongod数据

时间:2017-05-18 11:31:42

标签: node.js mongodb express mongoose pug

有些人可以帮我把Jade的mongodb数据显示在学校时间表这样的表格中。

我的收藏包含以下json:

{
  "day" : "Tuesday",
  "time" : "10:30",
  "course" : "CE8224",
  "rollno" : "es14btech11010", "__v" : 0
}

这就是我如何使用Jade(timetable.jade)获取数据:

table(border='1')
each course in courses
    thead
        th=course.time
    tbody
        tr
            td=course.day
            td=course.course    

我想要以下结果:

enter image description here

结果应该占据表格。但我得到以下结果:

enter image description here

我一直在尝试另外一段代码来做到这一点。但是没有显示表格中的任何数据。 time.jade

- var M9=""
- var M10=""
- var M11=""
- var M12=""
- var M230=""
- var M4=""
- var T9=""
- var T10=""
- var T11=""
- var T12=""
- var T230=""
- var T4=""
- var W9=""
- var W10=""
- var W11=""
- var W12=""
- var W230=""
- var W4=""
- var TH9=""
- var TH10=""
- var TH11=""
- var TH12=""
- var TH1=""
- var TH230=""
- var TH4=""
- var M1=""
- var T1=""
- var W1=""
- var F9=""
- var F10=""
- var F11=""
- var F12=""
- var F1=""
- var F230=""
- var F4=""
table(border='1')
    thead
        th #
        th 9:00-10:00
        th 10:00-11:00
        th 11:00-12:00
        th 12:00-01:00
        th 01:00-02:30
        th 02:30-04:00
        th 04:00-05:30
    tbody
    each course in courses
        if(course.day=="Monday")
            if(course.time=="09:00")
            M9 =course.course
        if(course.time=="10:00")
            M10=course.course
        if(course.time=="11:00")
            M11=course.course
        if(course.time=="12:00")
            M12=course.course
        if(course.time=="02:30")
            M230=course.course
        if(course.time=="01:00")
            M1=course.course    
        if(course.time=="04:00")
            M4=course.course
    if(course.day=="Tuesday")
        if(course.time=="09:00")
            T9 =course.course
        if(course.time=="10:00")
            T10=course.course
        if(course.time=="11:00")
            T11=course.course
        if(course.time=="12:00")
            T12=course.course
        if(course.time=="01:00")
            T1=course.course    
        if(course.time=="02:30")
            T230=course.course
        if(course.time=="04:00")
            T4=course.course
    if(course.day=="Wednesday")
        if(course.time=="09:00")
            W9 =course.course
        if(course.time=="10:00")
            W10=course.course
        if(course.time=="11:00")
            W11=course.course
        if(course.time=="12:00")
            W12=course.course
        if(course.time=="01:00")
            W1=course.course    
        if(course.time=="02:30")
            W230=course.course
        if(course.time=="04:00")
            W4=course.course
    if(course.day=="Thrusday")
        if(course.time=="09:00")
            TH9 =course.course
        if(course.time=="10:00")
            TH10=course.course
        if(course.time=="11:00")
            TH11=course.course
        if(course.time=="12:00")
            TH12=course.course
        if(course.time=="01:00")
            TH1=course.course    
        if(course.time=="02:30")
            TH230=course.course
        if(course.time=="04:00")
            TH4=course.course
    if(course.day=="Friday")
        if(course.time=="09:00")
            F9 =course.course
        if(course.time=="10:00")
            F10=course.course
        if(course.time=="11:00")
            F11=course.course
        if(course.time=="12:00")
            F12=course.course
        if(course.time=="01:00")
            F1=course.course     
        if(course.time=="02:30")
            F230=course.course
        if(course.time=="04:00")
            F4=course.course
    tr
        td=Monday
        td=M9
        td=M10
        td=M11
        td=M12
        td=M1
        td=M230
        td=M4       

1 个答案:

答案 0 :(得分:0)

你绝对可以在这里使用更多循环:pen

- function ObjectId(id){return id}
- var courses = [{ "_id" : ObjectId("59137d074f187015b4e5164c"), "day" : "Tuesday", "time" : "10:30", "course" : "CE8224", "rollno" : "es14btech11010", "__v" : 0 }]
- var days = ["Monday","Tuesday","Wednesday"]
- var times = ["9:00","10:30","12:00"]
table(border='1')
  thead
    each day in days
      th=day
  tbody
    each day in days
      tr
        each time in times
          td(style="height:20px")
            each course in courses
              if course.day == day && course.time == time
                =course._id