【问题标题】:How to ignore the text after some particular length using Angular.js如何使用 Angular.js 在特定长度后忽略文本
【发布时间】:2016-04-06 00:10:51
【问题描述】:

我正在从数据库中获取一些数据并将它们显示在表格中。我需要当任何列值将文本字符超过某个特定长度时,它将显示到该长度,其他将被替换为点 (i.e-.....)。

我在下面提供我的代码。

<table class="table table-bordered table-striped table-hover" id="dataTable" >
<thead>
<tr>
<th>Sl. No</th>

<th>Specification</th>

</tr>
</thead>

<tbody id="detailsstockid">
<tr ng-repeat="pro in productDataList">
<td>{{$index+1}}</td>
<td>{{pro.specification}}</td>
</tr>   
</tbody>
</table>

Specification 的上述代码中包含一些段落。我需要在这里paragraph 应该显示最多30 字符,如果超过了剩余的文本将替换为....

【问题讨论】:

标签: javascript angularjs


【解决方案1】:

看看limitTo

你可以这样做

{{ pro.specification | limitTo: 30 }} {{ pro.specification.length &gt; 30 ? '...' : '' }}

限制为30个字符,如果超过30个,则在末尾添加省略号

【讨论】:

    【解决方案2】:

    试试这个: {{ pro.specification.substr(0,30) + '...' }}

    【讨论】:

    • @UtsavShah 的解决方案肯定是 Angular 的做法。我更喜欢使用它作为我的解决方案,因为它的输入更少:)
    猜你喜欢
    • 2013-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多