簡體   English   中英

Laravel Yajra 數據表未使用 HTML 呈現所有列

[英]Laravel Yajra Datatables not render all columns with 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>

並且完美運行!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM