【发布时间】:2016-03-20 20:17:45
【问题描述】:
想象一下下面的数据库。
// 'Article' Schema
{
subject : 'Hello world',
content : 'I want to display this content partially.
The content would has verbose text like long
blabla...........blabla.......blabla......blabla...........
blabla.......blabla......blabla...........b........
and even more, It would has <img src=".......jpg"/>
}
现在我将这些数据渲染到某个 ejs 文件中,
<table>
<% Articles.forEach(function(article, index){ %>
<tr>
<td> <%= article.subject %> </td>
<td> <%= article.content %> </td>
</tr>
<% }) %>
</table>
// To don't display verbosely, give style attribute (Of course, on top of html)
<style>
td { white-space: nowrap; overflow: hidden; }
</style>
但是这样,它可能会降低应用程序的性能,对吧?如果一页有 10、20、30 篇文章,服务器会尝试显示全部内容。我想做的是一些内容摘要,我该如何巧妙地做到这一点?
【问题讨论】:
标签: javascript node.js express ejs