Express.js 到 EJS 部分渲染数据

Express.js to EJS rendering data partially

想象一下下面的数据库。

// '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 篇文章,服务器将尝试显示所有这些东西。我想做的是一些内容摘要,请问如何巧妙地做到这一点?

对于总结性的内容,在最后显示带省略号的开头几段文字

<table>
<% Articles.forEach(function(article, index){ %>
    <tr>
       <td> <%= article.subject %> </td>
       <td> <%= article.content.substring(0,10) %> ...</td>
       <td> <a id="read_more" content_id="cont-id" href = "javascript:(void)"> read more..</a></td>
    </tr>
<% }) %>

然后使用 ajax 应用程序在点击 read more 时获取完整数据取决于您使用的是 jquery 还是 angular 等

如果还有更多文章,则 paginationajax application or page refresh

在节点端创建 API 以您在页面加载期间所做的相同格式提供此内容数据或新文章