我使用Laravel 5进行项目。我从视图中显示表格,我想在点击此链接时传递它是数据值所有数据到JavaScript函数。我尝试了几种方法,但不能这样做。
@foreach ($basl_officers as $basl_officer)
<tr>
<td><a href="#" onClick="functionOne($basl_officer)" >{{ $basl_officer->officerName }} </a></td>
<td align='center'>
{!! Form::open(['method' => 'DELETE', 'route'=>['basl_officers_page.destroy',$basl_officer->id]]) !!}
<a href="{{route('basl_officers_page.edit',$basl_officer->id)}}" class="btn btn-default btn-sm"> <span class="glyphicon glyphicon-pencil"></span> </a>    
<button type="submit" class="btn btn-default btn-sm" onclick="return confirm('Are you sure?')"> <span class="glyphicon glyphicon-trash"></span> </button>
{!! Form::close() !!}
</td>
</tr>
@endforeach
JavaScript代码
<script type="text/javascript">
function functionOne(x) {
alert('You clicked the top text' + x);
}
function functionTwo() {
alert('You clicked the bottom text');
}
答案 0 :(得分:4)
你可以试试这个:
onClick="functionOne({{ json_encode($basl_officer) }})"
答案 1 :(得分:1)
我在.blade文件中使用此代码工作了。
<script>
var object = <?php echo json_encode($object) ?>;
console.log(object);
</script>
这是假设通过控制器提供对象。