首页 > 解决方案 > 在 p:textEditor 中添加或附加文本

问题描述

p:textEditor喜欢以下

<p:textEditor 
                id="editor"
                widgetVar="editor"
                value="#{xxxController.editorText}" 
                height="300" 
                placeholder="Enter your content"
                toolbarVisible="false"/>

有以下命令按钮来添加/附加值p:textEditor

<p:commandButton onclick="insertTag('[myValue]')" value="myValue" type="button" />

JavaScript
<script>
             
        function insertTag( t )
        {
            PF( 'editor' ).insertText( t ) ;
        }
        </script>

但是SCRIPT5007: Unable to get property 'insertText' of undefined or null reference当我尝试单击<p:commandButton.

那么我们如何使用 widgetVar 或 JavaScript 来插入/追加文本p:textEditor呢?

版本详情

JSF 2.2,PrimeFaces 6.2

标签: jsfprimefacestext-editor

解决方案


你需要这样做......一旦你有了小部件,“编辑器”变量就是 QuillJS 对象。

PF('editor').editor.insertText(0, 'Hello', 'bold', true);

请参阅:https ://quilljs.com/docs/api/#inserttext

请参阅:https ://quilljs.com/docs/api/#getlength


推荐阅读