无法使DataTables与Jade一起使用

时间:2017-06-17 12:54:15

标签: javascript node.js twitter-bootstrap pug

我编写了以下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

1 个答案:

答案 0 :(得分:3)

您的网页中存在错误。

您缺少thead标记。 DataTable仅适用于具有thead和tbody

的表

解决您的问题的方法是添加thead代码

&#13;
&#13;
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
&#13;
&#13;
&#13;