如何创建一个在MongoDB中将输入另存为html的Mongoose模式 [英] How to create a Mongoose schema that saves input as html in mongodb

查看:59
本文介绍了如何创建一个在MongoDB中将输入另存为html的Mongoose模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个带有管理面板的博客网站,用户可以在其中使用文本编辑器tinyMCE编写博客内容的正文.当前,我的博客正文架构设置为字符串,但是每次我写博客时,您都可以在博客周围看到html标记,并且该标记不会被识别为html.将模式设置为字符串是否有问题?

I am creating a blog website with an admin panel in which a user can write the body of the blog's content in the text editor tinyMCE. Currently my schema for blog body is set to string but everytime I write a blog you can see the html marks around the blog and the markup is not recognized as html. Is this an issue with the schema being set to string?

推荐答案

我以类似的方式在项目中使用它.我将tinyMCE内容作为字符串保存到mongo,因此与html标签一起保存.如果要在tinyMCE编辑器中显示这些内容,则必须使模板语言将未转义的值输出到模板中.可以说您的数据存储为description.如果您使用ejs,则可以使用此<%- description %>而不显示html标签.

I use it in my projects in a similar way. I save tinyMCE content to mongo as a string and thus is saved with the html tags. If you want display these contents out of tinyMCE editor you have to make the template language output the unescaped value into the template. Lets say that your data are stored as description. If you use ejs you can display it without html tags using this <%- description %>.

这篇关于如何创建一个在MongoDB中将输入另存为html的Mongoose模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆