Php jTable不显示JSON数据
我试图获取Laravel控制器提供的JSON数据,并将其显示在jQuery jTable中。表在请求数据时接收数据,但从不在表中显示数据 我有以下代码的jTable设置:Php jTable不显示JSON数据,php,jquery,json,laravel,jquery-jtable,Php,Jquery,Json,Laravel,Jquery Jtable,我试图获取Laravel控制器提供的JSON数据,并将其显示在jQuery jTable中。表在请求数据时接收数据,但从不在表中显示数据 我有以下代码的jTable设置: $('#items').jtable({ title: 'Items', useBootstrap: true, actions: { listAction: '{{ action('AdminAjaxItemsController@index', $in
$('#items').jtable({
title: 'Items',
useBootstrap: true,
actions: {
listAction: '{{ action('AdminAjaxItemsController@index', $invoice->id) }}',
createAction: '{{ action('AdminAjaxItemsController@store') }}',
updateAction: '{{ action('AdminAjaxItemsController@update') }}',
deleteAction: '{{ action('AdminAjaxItemsController@destroy') }}'
},
fields: {
id: {
key: true,
list: false
},
invoice_id: {
input: function (data) {
return '<input type="hidden" name="invoice_id" value="{{ $invoice->id }}" />';
}
},
quantity: {
title: 'Qty',
width: '5%'
},
name: {
title: 'Name',
width: '20%'
},
description: {
title: 'Description',
width: '35%'
},
cost_per_unit: {
title: 'Price',
width: '10%',
},
unit_label: {
title: 'Unit Label',
width: '10%',
},
tax: {
title: 'Tax',
width: '10%',
},
discount: {
title: 'Discount',
width: '10%',
}
}
});
以下是为listAction提供的JSON:
{"Result":"OK","Record":[{"id":"4","quantity":"1.0","invoice_id":"4","name":"Test Item","description":"None","cost_per_unit":"5.0","unit_label":"hour","tax":"0.0","discount":"0.0","created_at":"2014-10-05 19:49:29","updated_at":"2014-10-05 19:49:29"}]}
最后是JS控制台中的错误:
[Error] TypeError: undefined is not an object (evaluating 'e.length')
each (jquery-1.10.2.js, line 4)
_addRecordsToTable (jquery.jtable.js, line 548)
(anonymous function) (jquery-ui.min.js, line 6)
completeReload (jquery.jtable.js, line 446)
success (jquery.jtable.js, line 488)
success (jquery.jtable.js, line 1192)
c (jquery-1.10.2.js, line 4)
fireWith (jquery-1.10.2.js, line 4)
k (jquery-1.10.2.js, line 6)
r (jquery-1.10.2.js, line 6)
我认为问题在于它是listAction,保存时返回记录。您应该尝试在
索引中更改方法:
$res['Record'] = $items;
致:
当然,它不起作用,因为您将PHP与javascript混合使用。
$res['Record'] = $items;
$res['Records'] = $items;