0

我的表中有一个长列属性,它是一个标记,我希望它显示在两行而不是一行中,因为该标记占用了大量的表空间。

例如:“ 44b4bf4c01261542c9e34701fe435e55

代码片段:

<table class="table table-striped table-hover" id="admin_data_table">
  <thead>
    <tr>
    <th>request</th>
    </tr>
  </thead>
  <tbody> 
    <tr>
    <td><%= @request.token %></td>
    </tr>
  <tbody>
</table>

我怎样才能使这个长值44b4bf4c01261542c9e34701fe435e55更短,例如:

44b4bf4c012615
42c9e34701fe
435e55
4

3 回答 3

1

我同意这是一个前端问题。你可以在你的css中试试这个

table td 
{
  table-layout:fixed;
  width:20%; 
  overflow:hidden;
  word-wrap:break-word;
}

希望有帮助

于 2013-10-30T21:07:05.243 回答
1

您可以使用 String 的 scan 方法将其分解为位,然后将其重新组合在一起。这是一个示例,将其分解为每行最多 15 个字符。

> str = "44b4bf4c01261542c9e34701fe435e55"
 => "44b4bf4c01261542c9e34701fe435e55"
> puts str.scan(/.{0,15}/).join("\n")
44b4bf4c0126154
2c9e34701fe435e
55
于 2013-10-30T20:01:14.197 回答
1

这是一个前端视图问题。您应该使用 HTML 或 CSS 来处理列的宽度,而不是转换数据本身。

您可以通过设置 HTML 宽度来做到这一点,例如:

<table class="table table-striped table-hover" id="admin_data_table">
  <thead>
    <tr>
    <th width='10%'>request</th>
    </tr>
  </thead>
  <tbody> 
    <tr>
    <td width='10%'><%= @request.token %></td>
    </tr>
  <tbody>
</table>

您可以通过以下方式使用 css:

admin_data_table .token-column { width: 10% }

或者,如果您仍然想转换后端生成的数据,您可以使用 ruby​​ 拆分令牌字符串,如下所示:

<%= @token.each_slice(10) # will produce an array of chunks of 10 characters %>
于 2013-10-30T20:01:39.680 回答