【问题标题】:CKEditor, MongoDB, and NodeJs: Text is displayed in HTML FormatCKEditor、MongoDB 和 NodeJs:文本以 HTML 格式显示
【发布时间】:2020-10-29 10:29:38
【问题描述】:

我目前正在构建我的第一个博客站点,我正在使用 CKEditor v4.14.1 来允许用户制作格式化的博客条目。但是,用户输入在网页上显示为 HTML 而不是格式化文本。我也在使用 MongoDB 来存储博客条目。

这是用户输入:

这是网页上的输出:

new.ejs

<form action="/posts" method="POST" enctype="multipart/form-data">
  <div class="input-area">
    <textarea name="post[body]" id="editor" placeholder="Body"></textarea>
  </div>
  <input type="submit" id="submit">
</form>

<script>
  CKEDITOR.replace('editor')
</script>

MongoDB 发布架构

const PostSchema = new Schema({
  body: String
})

PostSchema.plugin(mongoosePaginate)
module.exports = mongoose.model('Post', PostSchema);

控制器/posts.js

const Post = require('../models/post');

// Posts Create
async postCreate(req, res, next) {
  let post = new Post(req.body.post);
  post.body = req.body.post.body;
  await post.save();
}

show.ejs

<div><%= post.body %></div>

【问题讨论】:

    标签: javascript html node.js mongodb ckeditor


    【解决方案1】:

    我的 show.ejs 应该是

    <div><%- post.body %></div>
    

    而不是

    <div><%= post.body %></div>
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-08
    • 2020-05-02
    • 1970-01-01
    • 2012-08-04
    相关资源
    最近更新 更多