我正在尝试从数据库中获取数据并显示在jquery DataTable中,但是数据未显示在DataTable中。表是
ordered_books with attributes 'BookID', 'BilledNum','BilledDate', 'Qunatity', 'Price', 'Remarks'
查看页面代码
<table id="showBooksIn" class="table table-bordered">
<thead>
<tr>
<th>BOOK ID</th>
<th>BILLED DATE</th>
<th>BILLED NUMBER</th>
<th>QUANTITY</th>
<th>PRICE</th>
<th>REMARKS</th>
</tr>
</thead>
</table>
<script type="text/javascript">
$(document).ready(function(){
$('#showBooksIn').DataTable({
"processing":true,
"serverside":true,
"ajax":{{route('data')}}
"columns":[
{"data": "BookID"},
{"data": "BilledNum"},
{"data": "BilledDate"},
{"data": "Qunatity"},
{"data": "Price"},
{"data": "Remarks"},
]
});
});
</script>
控制器代码
public function index()
{
return view('pages.booksin', $this->fetchData());
}
function fetchData()
{
$ordered_books = OrderedBook::select('BookID', 'BilledNum','BilledDate', 'Qunatity', 'Price', 'Remarks');
return Datatables::of($ordered_books)->make(true); //return an instance of the class or interface you request
}
型号代码
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class OrderedBook extends Model
{
//
}
路线代码
Route::resource('/order','OrderedBookController');
Route::get('/order/data','OrderedBookController@fetchData')->name('data');
我认为问题出在DataTable javascript代码上。但我不确定。请帮忙!!!
答案 0 :(得分:1)
答案 1 :(得分:1)
尝试更改
for (const selectItem1 of this.mwork.text){
this.textq = selectItem1.Question;
for (const selectItem2 of this.mwork.text){
this.texto = selectItem2.options;
}
}
答案 2 :(得分:0)
尝试用这样的引号包裹您的AJAX路线,
'{!! route("data") !!}'
答案 3 :(得分:0)
name
索引也需要在columns
上显示,例如:
"columns":[
{data: "BookID", name: "BookID"},
{data: "BilledNum", name: "BilledNum"},
{data: "BilledDate", name: "BilledDate"},
{data: "Qunatity", name: "Qunatity"},
{data: "Price", name: "Price"},
{data: "Remarks", name: "Remarks"},
]
将双引号从
data
而不是"data"
改为data
。
因此,如果需要,您可以复制并粘贴以上代码。