DataTable未显示表格

我正在尝试将dataTables合并到我的帖子索引中。我让表格出现,但是表格列中没有显示信息

我尝试按照他们所说的那样实现DataTables,并保持显示数据的正常方式,以确保获得结果

我使用

<link rel="stylesheet" href="//cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.js"></script>
    <script src="//cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>

我使用以下表格创建表格:

<table class="display" id="postsTable">
    <thead>
    <tr>
        <td>ID</td>
        <th>Title</th>
        <th>Slug</th>
        <th>Subtitle</th>
        <th>Content</th>
    </tr>
    </thead>
    <tbody>
    @foreach($posts as $post)
        <tr>
            <td>{{$post->id}}</td>
            <td>{{$post->Title}}</td>
            <td>{{$post->Slug}}</td>
            <td>{{$post->Subtitle}}</td>
            <td>{{$post->Content}}</td>
        </tr>
        @endforeach
    </tbody>
</table>


</body>
<script>
    $(document).ready( function () {
    $('#postsTable').DataTable();
    } );
</script>

而且我确定自从使用后,我可以得到我的posts表的结果。

<h1 class="title">Posts Table</h1>
<form action="/posts/create" id="myTable">
    <div class="field">
        <div class="control">
            <button type="submit" class="button is-link">Create New Post</button>
        </div>
    </div>
</form>

@foreach ($posts as $post)
    <li>
        <a href="/posts/{{ $post->id }}">
            {{$post->title}}
        </a>
    </li>
@endforeach

我得到结果。

感谢任何帮助,因为我在任何地方都找不到可行的解决方案。

pdschenxu 回答:DataTable未显示表格

查看代码后,我意识到我在尝试获取的属性名称上有错字。而不是“标题”,应该是“标题”等

本文链接:https://www.f2er.com/3133556.html

大家都在问