传递参数在一个JavaScript函数中的雄辩ORM中 [英] Passing parameter in Eloquent ORM inside a javascript function
问题描述
function kpi_values(d){
//`d`是原始数据对象行
var $ id = d.id;
return'< table>'+
'< thead>'+
'< tr>'+
'< th> Month< / th&
'< th> Value< / th>'+
'< th>注释< / th>'+
'< / tr>'+
' ; $ / $
'@ ,'+ $ id +')'+
//这里没有记录
// - > where(kpi_id,$ id) - >这给出一个错误
' - > 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>'
}
我收到的错误是:
e09c19f3dff5443f7b05b7c3c3e2f2a2第66行中的ErrorException:
未定义的变量:id
编辑1
我只是意识到 var $ id
不是一个php变量,所以它不会这样工作。所以我通过用<?php $ id = / *的问题* /?>替换
var $ id = d.id
但是,我不能将 d.id
作为一个值传递给该变量。
这不会像你想要的那样工作。你最好和你的原始方法。如果你发布你以前的问题的数据库结构,我可以看看它。
I have a Laravel app where i'm using jQuery DataTables Master/Details to show some extra information. I can show the data to the child row, but I want it filtered first, depending on the row selected. The information that i want to retrieve is not on the original data source which I used to create the DataTable. Therefore i want to pass the record id to the new query that I am using directly from the javascript. Here is the code:
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>'
}
The error that I receive is:
ErrorException in e09c19f3dff5443f7b05b7c3c3e2f2a2 line 66:
Undefined variable: id
EDIT 1
I just realised that var $id
is not a php variable therefore it will not work like that. So I updated my code by replacing var $id = d.id
with <?php $id = /*the problem*/ ?>
however I cannot pass the d.id
as a value to that variable.
This won't work the way you would like. You are better going with your original approach. If you post you db structure on your previous question I can take a look at it.
这篇关于传递参数在一个JavaScript函数中的雄辩ORM中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!