为 bootstrap-table 生成的列中的文本添加超链接

Rod*_*eno 3 bootstrap-table pug

使用 Node + Jade 正在创建一个将显示大量用户列表的表,所以我决定使用 bootstrap-table 并且我发现了一个有很多可能性的很棒的库。

我目前使用分页来不显示表格中的信息,目前表格只有两列,第一列是选择多个用户的复选框,第二列只是用户的用户名。该表看起来不错,但我会添加一个链接来详细介绍用户(例如:/user/:id),并将此链接添加到我的第二列。

目前我的代码如下所示:

table(data-toggle='table', data-url='users.json', data-pagination='true', data-search='true', data-striped='true')
  thead
    tr
      th(data-checkbox='true')
      th(data-field='username') Username
Run Code Online (Sandbox Code Playgroud)

我只想在包含用户名的文本中添加一个超链接

小智 5

在您的 HTML 表格中:

<th data-field="user_name" data-formatter="LinkFormatter">Computer</th>
Run Code Online (Sandbox Code Playgroud)

在你的 javascript 中:

function LinkFormatter(value, row, index) {
  return "<a href='/userid/id:"+row.id+"'>"+value+"</a>";
}
Run Code Online (Sandbox Code Playgroud)