【问题标题】:Add a jQuery table from a simple .php to .blade.php Laravel5将 jQuery 表从简单的 .php 添加到 .blade.php Laravel5
【发布时间】:2017-03-24 23:49:50
【问题描述】:

我有一个带有导航栏的网站(在 main.blade.php 中)。我创建了一个 jQuery 表,但不是在刀片视图中,而是作为一个简单的 .php。如何设置内容部分并将其添加到刀片?谢谢!

路线:

web.php

旧(刀片中的一个简单页面):

Route::get('/manageclasses', ['as' => 'manageclasses', 'uses' => 'UserView\AdminController@manageclasses']);

新的(带有表格的简单页面):

Route::get('/manageclasses',['as' => 'manageclasses',function(){
  $manageclasa = App\Elevi::all();
  return View::make('table')->with('manageclasa', $manageclasa);
}]);

我想在其中添加表格的刀片布局

@extends('layouts.master')
@extends('layouts.navbar')
@extends('layouts.sidebar')


@section('content')
<h3 class="white-text">Manage Page</h3>

@endsection

我的新表格布局

<!doctype html>
<html lang="en">
   <head>
      <meta charset="utf-8">
      <title>Manage Clasa</title>
      <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
      <script src="//ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
      <link rel="stylesheet" type="text/css" href="//ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
   </head>


   <body>
      <h1>Elevi clasa</h1>
      <table>
      <thead>
         <tr>
            <th>Nume</th>
            <th>Prenume</th>
         </tr>
      </thead>
      <tbody>
         <?php foreach ($manageclasa as $elev): ?>
         <tr>
            <td><?php echo $elev['nume'] ?></td>
            <td><?php echo $elev['prenume'] ?></td>
         </tr>
         <?php endforeach; ?>
      </tbody>
      </table>

      <script>
         $(function(){
            $("table").dataTable();
         });
      </script>
   </body>
</html>

【问题讨论】:

  • 这里有什么问题?
  • 我无法将表格添加到刀片中。我尝试了多种方法,但都不成功
  • 所以我需要一个如何制作它的建议

标签: php laravel laravel-5 blade laravel-blade


【解决方案1】:

你正在返回一个 Eloquent 对象。试试这个:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Manage Clasa</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
<link rel="stylesheet" type="text/css" href="//ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
</head>


<body>
<h1>Elevi clasa</h1>
<table id="elevi-clasa">
<thead>
<tr>
  <th>Nume</th>
  <th>Prenume</th>
</tr>
</thead>
<tbody>
@foreach($manageclasa as $elev)
<tr>
  <td>{{ $elev->nume }}</td>
  <td>{{ $elev->prenume }}</td>
</tr>
@endforeach
</tbody>
</table>

<script>
$(function(){
$("#elevi-clasa").dataTable();
});
</script>
</body>
</html>

【讨论】:

  • 你不需要原来的&lt;?php foreach ($manageclasa as $elev): ?&gt;
  • 感谢您的反馈。你说得对。我已经删除了额外的 foreach 行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-01-22
  • 1970-01-01
  • 2012-10-30
  • 2015-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多