2016-09-27 15 views
1

我有真正的麻烦了解如何用鹅毛笔工作...如何在现有的数据读入奎尔JS

保存数据不作为的问题非常简单的:)

我有点憋屈两点

  1. 如何鹅毛笔
  2. 如何分析所保存的数据来创建一个静态页面
编辑保存的数据

谁能提供任何意见如何加载三角洲

{"ops":[{"insert":"this is a test bit of text\n"}]} 

回鹅毛笔编辑器,以及如何解析输出来创建页面?

在此先感谢您的回复!

回答

2

使用setContents插入增量:

quill.setContents({ 
    "ops":[ 
     {"insert":"this is a test bit of text\n"} 
    ] 
}); 

http://codepen.io/anon/pen/VKWZLd

,您可以访问原始的HTML:

var html = document.querySelector(".ql-editor").innerHTML 

如果您正在使用原始的HTML工作,你需要清理它在你使用它之前。

+0

感谢您的回复。所以我在使用setContents API之前已经尝试过了,但它只是输出文本字符串“{”ops“:[{”insert“:”this is a test bit of text \ n“}]}”并且不创建表单。 – Tony

+0

上面的codepen链接向您展示了setContents的现场演示。通过表单来表示文本编辑器? –

-1

所以我设法找到解决方法,不知道它是否是正确的方法,但它的工作原理。

原来是javascript转义传递给它的数据。

本质上讲,当窗体未提交出错的数据添加回隐藏的输入字段,然后javascript中就有记载它...

HTML表单:

<input name="post" id="post" type="hidden" data-post-id="{{ old('post') }}"> 

的Javascript:

var postId = $('#post').data("post-id"); 
quill.setContents(postId); 
1
  • 创建编辑器(以下示例为只读版本)
  • 找到你的目标(要显示的文本)
  • 解析你的字符串内容
  • setContents对编辑器

var quill = new Quill('#editor-container', { modules: { toolbar: [] }, readOnly: true, theme: 'bubble'}); 
var $target = $('#editor-container'); 
var $content = JSON.parse($target[0].innerText); 
quill.setContents($content); 
3

这对我的作品。愿它能帮助一个人。

editor.root.innerHTML = "<p><strong class=\"ql-size-large\"><em><s><u>This would be the text that we are going to show in the editor with pre-formatting.<\/u><\/s><\/em><\/strong><\/p>"; 

这里editor将成为您的羽毛笔实例。

感谢此信LINK