传递参数在一个JavaScript函数中的雄辩ORM中 [英] Passing parameter in Eloquent ORM inside a javascript function

查看:74
本文介绍了传递参数在一个JavaScript函数中的雄辩ORM中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Laravel应用程序,我正在使用jQuery DataTables Master / Details显示一些额外的信息。我可以将数据显示给子行,但是我要先将其过滤,这取决于所选的行。我想要检索的信息不是我用于创建DataTable的原始数据源。因此,我想将记录ID传递给我直接从javascript使用的新查询。这是代码:

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆