我正在使用Laravel 5和Bootgrid Pagination。我打算稍后使用它,所以我正在学习它并玩弄它但我无法使它工作。在我的浏览器控制台中,我得到了
Uncaught TypeError: Cannot read property 'length' of undefined
我不知道这是否是我传递的数据格式。
这是html
<table id="grid-data" class="table table-condensed table-hover table-striped" data-toggle="bootgrid" data-ajax="true" data-url="api/deliverytracker">
<thead>
<tr>
<th data-column-id="id" data-identifier="true">ID</th>
<th data-column-id="sender">Sender</th>
<th data-column-id="received">Recieved</th>
</tr>
</thead>
</table>
在我的api / deliverytracker路线中
Route::any('api/deliverytracker', 'DeliveryTrackerController@deliveryIndexApi');
然后我在DeliveryTrackerController中的功能
public function deliveryIndexApi()
{
$data = array(
array('id' => '1', 'sender' => '123@test.de', 'received' => '2014-05-30T22:15:00'),
array('id' => '2', 'sender' => '123@test.de', 'received' => '2014-05-30T22:15:00'),
);
return json_encode($data);
}
我错过了什么吗?我试图控制记录我的$ data结果
[{"id":"1","sender":"123@test.de","received":"2014-05-30T22:15:00"},{"id":"2","sender":"123@test.de","received":"2014-05-30T22:15:00"}]
谢谢!
答案 0 :(得分:0)
您需要正确返回JSON。
$data = array(
"current" => 1,
"rowCount" => 10,
"rows" => array(
array('id' => '1', 'sender' => '123@test.de', 'received' => '2014-05-30T22:15:00'),
array('id' => '2', 'sender' => '123@test.de', 'received' => '2014-05-30T22:15:00')
),
"total" => 1123
);