猿问

Laravel 数据表以 JSON 格式显示

我必须以数据表的形式显示数据我使用 YajraBox Laravel 数据表来做到这一点,但它以 JSON 格式显示


/*Route code*/

Route::get('/editing','TlController@modif')->name('modif'); 


/*the Controller code*/

    public function modif(){



      return DataTables::of(Weekends::query())->make(true);

    } 

/*View code*/

@extends('layouts.master')

@section('containers')

<table class="table table-bordered" id="weekends-table">

    <thead>

            <tr>

            <th>idm</th>

            <th>fday</th>

            <th>sday</th>

            <th>id</th>

            <th>updated_at</th>

            <th>created_at</th>

        </tr>

    </thead>

<script>

$( document ).ready(function() {

    $('#weekends-table').DataTable({

        processing: true,

        serverSide: true,

        ajax: '{!! route('modif') !!}',

        columns: [

            { data: 'idm', name: 'id' },

            { data: 'fday', name: 'first day of weekend' },

            { data: 'sday', name: 'second day of weekend' },

            { data: 'created_at', name: 'created_at' },

            { data: 'updated_at', name: 'updated_at' }

        ]

    });

});

</script>

@endsection

吃鸡游戏
浏览 159回答 2
2回答

手掌心

正如第一个评论者所说,<thead>如果它可以工作,请尝试添加它,也不要忘记结束</table>标记:<tbody><tr><td colspan="6">No data.</td></tr></tbody>

牛魔王的故事

&nbsp; &nbsp;<tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>idm</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>fday</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>sday</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>updated_at</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>created_at</th>&nbsp; &nbsp; &nbsp; &nbsp; </tr>您的 js 中有 5 个参数,而 .js 中有 6 个参数。您应该在 js 和表的内部标记中传递确切数量的参数。:)
随时随地看视频慕课网APP
我要回答