首页 > 解决方案 > Laravel Yajra 数据表不使用 HTML 渲染所有列

问题描述

我在 Laravel 中使用 Yajra 数据表,我需要用 HTML 代码渲染四列,但其中只有 3 列被成功渲染。

!我不知道为什么没有呈现“兴趣”列。1

这是该列的代码(stackoverflow 不能让我发布所有方法):

        return DataTables::of($users)
            ->addColumn('interests', function($query) {
                $userData = UserData::where('user_id', $query->id)->first();
                if(empty($userData->interests) || is_null($userData->interests))
                    return '<a href="javascript:;">No iterests selected</a>';

                $html = '';
                $list = Interests::List();

                $myInterestsIDs = explode('|', $userData->interests);

                foreach($myInterestsIDs as $id)
                {
                    if(is_null($id) || empty($id))
                        continue;

                    $html .= '<span class="badge badge-secondary">' . $list[$id-1] . '</span>';
                }

                return $html;
            })
            ->rawColumns(['nda', 'access', 'interests', 'actions'])
            ->make(true);
    }

我找到了它不呈现 HTML 的原因。这是因为车把

 <script id="details-template" type="text/x-handlebars-template">
     <table class="table">
          <thead>
              <th>Approval</th>
              <th>Status</th>
              <th>Interests</th>
              <th>Total Access</th>
              <th>Last Access</th>
          </thead>
          <tbody>
              <tr>
                 <td>@{{approval}}</td>
                 <td>@{{status}}</td>
                 <td>@{{interests}}</td>
                 <td>@{{count_login}}</td>
                 <td>@{{last_login}}</td>
              </tr>
          </tbody>
     </table>
 </script>

标签: phplaravelhandlebars.jsyajra-datatable

解决方案


我变了

<td>@{{interests}}</td>

<td>@{{{interests}}}</td>

并且完美运行!


推荐阅读