【问题标题】:Unable to get DataTables to work with Jade无法让 DataTables 与 Jade 一起使用
【发布时间】:2017-11-20 03:41:00
【问题描述】:

我编写了以下 Jade/Pug 模板,但它没有启动数据表,我看不出我做错了什么。有人能发现问题吗?

html
    head
        title= 'Feed List'
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        link(href="//maxcdn.bootstrapcdn.com/bootswatch/3.3.0/flatly/bootstrap.min.css", rel="stylesheet")
        link(href="//cdn.datatables.net/v/dt/dt-1.10.15/datatables.min.css", rel="stylesheet")

    body
        div.container.jumbotron
            h1.header NSE Corporate Announcements
            h3.header Top Annoucements by corporates listed on NSE
        div.container
            script(src='//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js')
            script(src='//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js')
            script(src='//cdn.datatables.net/v/dt/dt-1.10.15/datatables.min.js')
            script.
                $(document).ready(function() {
                    $('#resultTable').DataTable();
                });
            div#dataToShow
                table#resultTable.table.table-hover.datatables
                    tr.head
                        th='Ticker'
                        th='Link'
                        th='Date'
                        th='Description'
                    tbody
                    for feed in feedList
                        tr
                            td= feed.ticker
                            td
                                a(href=feed.attachmentLink) #{feed.ticker}
                            td= moment(feed.dateAdded).format('DD-MM-YYYY HH:MM:SS')
                            td= feed.purposeText

【问题讨论】:

  • 控制台有错误吗?

标签: javascript node.js twitter-bootstrap datatables pug


【解决方案1】:

您的网页中有错误。

您缺少thead 标签。 DataTable 仅适用于具有theadtbody 的表。

你的问题的解决方法是添加thead标签:

html
    head
        title= 'Feed List'
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        link(href="//maxcdn.bootstrapcdn.com/bootswatch/3.3.0/flatly/bootstrap.min.css", rel="stylesheet")
        link(href="//cdn.datatables.net/v/dt/dt-1.10.15/datatables.min.css", rel="stylesheet")

    body
        div.container.jumbotron
            h1.header NSE Corporate Announcements
            h3.header Top Annoucements by corporates listed on NSE
        div.container
            script(src='//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js')
            script(src='//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js')
            script(src='//cdn.datatables.net/v/dt/dt-1.10.15/datatables.min.js')
            script.
                $(document).ready(function() {
                    $('#resultTable').DataTable();
                });
            div#dataToShow
                table#resultTable.table.table-hover.datatables
                   thead
                      tr
                        th Ticker
                        th Link
                        th Date
                        th Description
                    tbody
                      for feed in feedList
                         tr
                            td= feed.ticker
                            td
                                a(href=feed.attachmentLink) #{feed.ticker}
                            td= moment(feed.dateAdded).format('DD-MM-YYYY HH:MM:SS')
                            td= feed.purposeText

【讨论】:

  • 进行了更改。现在数据表已呈现,但没有任何工作......
  • 进行了更改。现在数据表已呈现,但没有任何工作......表的第一行显示“表中没有可用数据”
  • 似乎是缩进错误。在 tbody 内缩进 for 循环。
  • 是的,这是 tbody 之后需要的额外缩进。抱歉 - 我和哈巴狗的第一天,所以需要更多地训练我的眼睛。非常感谢您的帮助!!
  • 1 请您渲染一个没有dataTable 的表格并检查表格是否有tbody。 2.在页面末尾添加document.ready
猜你喜欢
  • 1970-01-01
  • 2014-10-31
  • 2018-01-02
  • 2016-11-14
  • 2015-02-01
  • 2019-05-10
  • 2011-05-24
  • 2019-05-17
  • 2018-06-02
相关资源
最近更新 更多