【发布时间】:2015-09-29 09:06:19
【问题描述】:
我有一个 Laravel 应用程序,我在其中使用 jQuery DataTables Master/Details 来显示一些额外的信息。我可以将数据显示到子行,但我希望它首先过滤,具体取决于所选的行。我要检索的信息不在我用来创建 DataTable 的原始数据源上。因此,我想将记录 ID 传递给我直接从 javascript 使用的新查询。代码如下:
function kpi_values(d) {
// `d` is the original data object for the row
var $id = d.id;
return '<table>'+
'<thead>'+
'<tr>'+
'<th>Month</th>'+
'<th>Value</th>'+
'<th>Comment</th>'+
'</tr>'+
'</thead>'+
'<tbody>'+
'@foreach( \App\Reports::with("kpi")
->where("kpi_id",'+$id+')'+
//this gives no records
//->where("kpi_id",$id) -> this gives an error
'->orderBy("month","desc")
->take(5)
->get() as $report)'+
'<tr>'+
'<td>{{$report->month}}</td>'+
'<td>{{$report->value}}</td>'+
'<td>{{$report->comment}}</td>'+
'</tr>'+
'@endforeach'+
'<tbody>'+
'</table>'
}
我收到的错误是:
ErrorException in e09c19f3dff5443f7b05b7c3c3e2f2a2 line 66:
Undefined variable: id
编辑 1
我刚刚意识到 var $id 不是 php 变量,因此它不会那样工作。所以我更新了我的代码,将var $id = d.id 替换为<?php $id = /*the problem*/ ?>
但是我不能将 d.id 作为值传递给该变量。
【问题讨论】:
标签: javascript php laravel eloquent laravel-5