显示用户 .pug js 列表

Posted

技术标签:

【中文标题】显示用户 .pug js 列表【英文标题】:display list of user .pug js 【发布时间】:2022-01-23 18:47:31 【问题描述】:

我想将数据库中的所有医生显示为列表,我不知道如何在 pug 中使用列表,以及如何显示每个医生的医生信息,我到达的地方,请帮助,什么我应该编辑还是添加

app.get("/user/new_diagnosis",checkNotAuthenticated,(req, res) => 
    res.render("user-diagnosis", name: req.user.userName ,surname: req.user.userSurname );
    db.query(
      `SELECT * FROM doctor`,
        (err, results) => 
          if (err) 
            console.log(err);
          
           const Ndoc = results;
           console.log(results);
        
      );
  );

console.log(结果);输出

[
  RowDataPacket 
    doctorID: 1,
    hospitalName: 'momi',
    doctorName: 'adam',
    doctorSurname: 'rakii',
    doctorEmail: 'adam.rakii@gmail.com',
    doctorPassword: 'riro',
    created_at: null,
    updated_at: null
  ,
  RowDataPacket 
    doctorID: 2,
    hospitalName: 'hopi',
    doctorName: 'hajar',
    doctorSurname: 'rako',
    doctorEmail: 'hajar.hu@gmail.com',
    doctorPassword: 'dsj',
    created_at: null,
    updated_at: null
  
]
extends user-layout 

block content 
    div.container-fluid
        div(class=["row", "pt-4"])
            div(class=["col-md-3", "col-sm-5", "d-md-flex", "flex-column", "border-end"])
                h3(class=["text-black", "py-4", "text-center"]) Select A Doctor
                form.d-flex.mb-3(role="form", action="/", method="get")
                    input.form-control.me-2(id="doctor-search", name="doctor-search", type='search' placeholder='Search' aria-label='Search')
                    button.btn.btn-outline-success(type='submit') Search
                - var doctor_number = [1, 2, 3, 4 ,5, 6, 7, 8, 9, 10];
                each val in doctor_number
                    .list-group
                        a.list-group-item.list-group-item-action.d-flex.gap-3.py-3(href= `new_diagnosis/$val`, aria-current='true')
                            svg(xmlns="http://www.w3.org/2000/svg", , , fill="currentColor", class=["bi", "bi-person-circle", "pe-1"], viewBox="0 0 16 16")
                                path(d="M11 6a3 3 0 1 1-6 0 3 3 0 0 1 6 0z")
                                path(fill-rule="evenodd", d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm8-7a7 7 0 0 0-5.468 11.37C3.242 11.226 4.805 10 8 10s4.757 1.225 5.468 2.37A7 7 0 0 0 8 1z")
                            .d-flex.gap-2.w-100.justify-content-between
                                div
                                    h6.mb-0= "Doctor "+ val
                                    p.mb-0.opacity-75 Some placeholder content in a paragraph.
                                small.opacity-50.text-nowrap now
            div(class=["col-md-9", "col-sm-7", "px-4"])
                //-form(role="form", action="examination_card", method="post")

【问题讨论】:

【参考方案1】:
  ul
    each val in myArr
      li= val

确保从后端正确发送数据。 可以使用data[0].doctorName 访问该数组 对于您的情况:

   res.render("user-layout",doctors);

在 PUG 中:

ul
    each doctor in doctors
      li= doctor

更多关于这个: Iterations in Pug

【讨论】:

以上是关于显示用户 .pug js 列表的主要内容,如果未能解决你的问题,请参考以下文章

discord.js 如何从 fetchMessage 事件中获取“反应用户”列表?

如何使用 Webpack 捆绑 Express Js (NodeJs) 和 Pug 引擎?

我不能用express.js执行jade(pug)

PUG+Express+Jquery+bootstrap

在 vue.config.js 中添加 pug-plain-loader 配置

JS 根据数据属性选择显示选项