【问题标题】:how to add the dynamically added tr data at the top row of the table in pug?如何在 pug 表格的第一行添加动态添加的 tr 数据?
【发布时间】:2022-11-07 19:37:35
【问题描述】:

如何在 pug 表格的第一行添加动态添加的 tr 数据? 这里它在底部添加

我写的代码...
任何帮助将不胜感激...在此先感谢

<tbody>

        if records.length 

            each record, index in records

                - const sl = index + 1, id = record._id.toString();

                    tr(class="data record" data-id= id)

                        th(scope="row") #{sl}
                        td(class="name") #{record.studentName}
                        td(class="subject") #{record.subject}
                        td(class="theory") #{record.theory}
                        td(class="practical") #{record.practical}
                        td(class="total") #{record.total}
                        td
                            a(href="#" class="editBttn") Edit
                        td
                            a(href="#" class="delBttn") Delete

        else

            tr(class="data no-record")

                td(colspan="8") No records are available...


    </tbody>

【问题讨论】:

  • “动态添加的 tr 数据”到底是什么意思?
  • 动态添加表格行数据
  • 从表单的输入打印数据
  • 考虑颠倒record 列表/数组中项目的顺序。

标签: javascript html pug


【解决方案1】:

最简单的方法是在编译模板之前反转记录数组,但是如果你想在 pug 中这样做,你可以使用 while 循环并从最后一条记录开始 pugjs.org

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-09
    • 2012-02-11
    • 2013-09-05
    相关资源
    最近更新 更多