DataTables Laravel 5.4使用Ajax请求的未定义索引

时间:2017-07-11 23:36:38

标签: datatables laravel-5.4

我为 Laravel 5.4 使用 DataTables yajra / laravel-datatables-oracle 包。我希望在 screen_name 列中显示 screen_name screen_name 位于JSON对象中( JSON结果)。

Ajax脚本代码:

$(document).ready(function() {
    $('#logs-table').DataTable({
        processing: true,
        serverSide: true,
        stateSave: true,
        ajax: 'api/ajax-file',
        columns: [
            { data: 'credentials.screen_name', name: 'credentials.screen_name' }
        ],
        aoColumns: [
            {
                aTargets: [0],
                mData: 'credentials.screen_name',
                mRender: function (data, type, full) {
                    return '<strong>' + data + '</strong>';
                }
            }
        ]
    });
});

HTML code:

<table class="table table-hover table-striped" id="logs-table">
    <thead>
        <tr>
            <th>User</th>
        </tr>
    </thead>
</table>

JSON结果:

{
    "draw":0,
    "recordsTotal":208,
    "recordsFiltered":208,
    "data": [{
        "_id":"5960e2f59f9d5158f7129d82",
        "credentials":{
            "id":"1",
            "id_str":"1",
            "name":"User 1",
            "screen_name":"user1"
        },
        ...
    }]
}

Yajra查询:

public function ajax(Request $request)
{
    $users = User::all();
    return Datatables::of($users)->make(true);
}

我有这个错误:

enter image description here

0 个答案:

没有答案