php - 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>
解决方案
我变了
<td>@{{interests}}</td>
至
<td>@{{{interests}}}</td>
并且完美运行!
推荐阅读
- javascript - 如何使用数据表在列过滤器中拆分值
- node.js - 谷歌移动友好的 url 测试工具给出 502 错误
- windows - CPU 进程在打开任务管理器时隐藏,但在关闭时运行(过度使用)
- c - 使用管道读写
- android - 如何在android中使用正则表达式验证editText
- android - Android,如何基于 api 29 为 arm64-v8a 创建 avd
- javascript - 从 ReactJS 编辑 Cloud Firestore 记录
- javascript - 如何使用 Firebase RealTime 数据库根据特定类别获取项目集合
- momentjs - 将矩范围与帆后端连接起来
- batch-file - 通过批处理脚本更改 PC 的主机名