我有一桌新闻:
export class News{
id: string;
name: string;
text: string;
admin: boolean;
users: Users;
}
我有一个返回 news.ts 列表的方法:
news: News[];
pageNews: News[];
getNews(): void {
//let MaxLength = 5;
this.newsService.getnews().subscribe(res => {
this.news= res;
this.pageNews= this.news.slice(0, 10);
}
);}
在 news.html 中:
<table class="table table-bordered table-striped" style="border: none;">
<thead>
<tr>
<td class="title-column">Id</td>
<td class="title-column">Name</td>
<td class="title-column">Text</td>
</tr>
</thead>
<tr *ngFor="let u of pageNews">
<td class="row-mid">{{u.id}}</td>
<td class="row-mid">{{u.name}}</td>
<td class="row-mid">{{u.text}}</td>
</tr>
</table>
但是当名字或文字太长时,我的表格会溢出,所以,我想在超过 20 个字符时截断我的名字和文字,然后放点。例子:
string s = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
result = 'aaaaaaaa...'
我在我的 news.ts 中尝试,但它不起作用
news: News[];
pageNews: News[];
getNews(): void {
//let MaxLength = 5;
this.newsService.getnews().subscribe(res => {
this.news= res.filter(e=>{e.name= e.name.substring(0,20) + '...',
e.text= e.text.substring(0,20) + '...';});
this.pageNews= this.news.slice(0, 10);
}
);}
汪汪一只猫
RISEBY
慕盖茨4494581
相关分类