如何将HTML元素从快递服务器发送到ejs?

时间:2020-02-06 15:32:36

标签: javascript jquery node.js express ejs

这是我的代码:-

app.get("/articles", function(req, res) {
const art=[]
let today=Articles.find(function(err,articles){
articles.forEach(function(ar){
art.push({
  posttitle: ar.title,
  posttext: ar.text
});

});
  res.render("articles.ejs", {
        article:art,
        userStatus:"SignUp",
   jq:$
  });
})

});

这是我的ejs代码:-

<%- include("header.ejs") %>
<% article.forEach(function(post){   %>
<h1><%= post.posttitle %></h1>
<% let text = post.posttext; %>
<p style="display:inline;"><%= text %></p> <a href="/posts/<%=post.posttitle %>"> Read More</a>
<% }); %>
<%- include("footer.ejs") %>

如何获取文章内容,以HTML形式显示,当前,如果转到此页面,我将获得字符串形式的文章内容(例如:如果post.posttext =“ ”,我得到的是而不是“ hi”。

我如何使其按预期工作?

0 个答案:

没有答案