将 JSON 转换为服务器端的 HTML
你好, 对于未来的问题或技术问题(非漏洞),GitHub的[讨论](https://github.com/artf/grapesjs/discussions)标签是最佳选择。 如果问题已解决,请关闭,或在[讨论](https://github.com/artf/grapesjs/discussions)->[问答](https://github.com/artf/grapesjs/discussions/categories/q-a)类别写一条详细的新消息(并关闭本期)。 感谢你的理解。
阅读下方完整回答 ↓问题
首先,感谢@artf这个了不起的项目。
我有个问题: 在服务器端(Node.js环境)能否轻松地将组件的JSON转换为HTML?如果可能的话,能给我一些建议吗?
客户端方面很简单: 我可以获取components-JSON (“JSON.stringify(editor.getComponents();')”)并保存到我的数据库。之后我可以重复使用组件('editor.setComponents();'),并让 HTML ('editor.getHtml();') 在浏览器中显示。不过就我而言,我必须在服务器端完成。
任何帮助都将不胜感激!
回答(4)
你好,
对于未来的问题或技术问题(非漏洞),GitHub的[讨论](https://github.com/artf/grapesjs/discussions)标签是最佳选择。
如果问题已解决,请关闭,或在[讨论](https://github.com/artf/grapesjs/discussions)->[问答](https://github.com/artf/grapesjs/discussions/categories/q-a)类别写一条详细的新消息(并关闭本期)。
感谢你的理解。
是的,如果你有任何互动内容,那可能行不通。幸运的是,我的申请情况并非如此。
也许你可以在服务器端安装Grapesjs(类似客户端),用来渲染,否则你得逆向工程渲染器。另一种选择是将生成的HTML也存储在数据库中。
谢谢你举报,@AdamTorma。 关于将JSON转换为服务器端HTML的好问题。推荐的组件方法是使用事件驱动的API。 从这里开始: 查看你所在模块的[GrapesJS文档](https://grapesjs.com/docs/) 寻找“on()”事件监听器方法 大多数操作可以通过监听编辑器和组件事件来实现 常见模式: “JavaScript 留意变化 editor.on('change', () => console.log('something changed')); 组件生命周期 editor.on('component:mount', (c) => console.log('com...
相关问答
通过相似的问题讨论继续研究。
问题 #3627
:我正在尝试复制页面,但由于 ID,样式无法应用,结尾的 -2,-3 发生了变化。
“JavaScript const duplicatePage = (编辑者) => { let components = editor.getHtml(); 令 css = editor.getCss(); 让newPage = 编辑器。Pages.add({ 样式:CSS,...
问题 #3176
'setStyle' 和 'setComponents' 选项参数未被考虑
版本: 0.16.30 你能重现演示中的bug吗? [x] 是的 [ ] 不 繁殖步骤:打开控制台执行 'editor.setComponents('', {avoidStore: true});'执行 'editor.setStyle('', {avoidStore: tru...
问题 #3779
Editor.getSelected().toHTML() 编码内联 JavaScript
葡萄JS版本[X] 我确认使用最新版本的GrapesJS你用的是什么浏览器? 最新款(镀铬)可复制演示链接 https://jsfiddle.net/4j1k0wde/24/描述一下那个虫子 如何复现这个漏洞?创建带有脚本标签的方块。使用 'editor.getSelected...
问题 #3654
Editor.setComponents(html)和pageManager.select(pageId)未加载js脚本
嗨,@artf据我所知,allowScripts:1 允许 grapesjs 加载脚本。我第一次加载着陆页时,它运行正常。它能加载所有JavaScript。之后,当我使用 editor.setComponents(html) 或 pageManager.select(pageI...
与此问题匹配的付费插件
根据问题关键词和标签相关性精选,助你更快交付。
正在加载付费插件推荐……
相关教程
关于同一主题的深入指南。
教程
GrapesJS DevTools: A Developer Panel Inside Your Editor
If you've ever debugged GrapesJS with console.log(editor.getSelected()) and a dozen throwaway event listeners — this post is for you.
教程
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
教程
Big Updates: TinyMCE 8 and Placeholder 2.0 for GrapesJS
In May we shipped major updates to two of our most popular GrapesJS plugins — TinyMCE Inline Text Editor and Placeholder.
浏览插件分类
直接跳转到市场上的插件分类页面。