[英]Quill Editor - unable to set data on click
我正在使用羽毛筆編輯器並在引導程序模式內使用它,並且在以JSON形式將數據插入data- *屬性中時工作正常
所以有什么問題 :
問題是,當我嘗試使用setContent api在主軸編輯器中設置數據時,它不起作用
/*
====================
Quill Editor
====================
*/
var quill = new Quill('#editor-container', {
modules: {
toolbar: [
[{ header: [1, 2, false] }],
['bold', 'italic', 'underline'],
['image', 'code-block']
]
},
placeholder: 'Compose an epic...',
theme: 'snow' // or 'bubble'
});
這是我的jsfiddle (在使用前請閱讀以下說明)
如何使用我的小提琴:
訣竅是將JSON字符串轉換回JSON對象:
從這里開始 : var dataText = $(this).attr('data-text');
為此 : var dataText = JSON.parse($(this).attr('data-text'));
var quill = new Quill('#editor-container', { modules: { toolbar: [ [{ header: [1, 2, false] }], ['bold', 'italic', 'underline'], ['image', 'code-block'] ] }, placeholder: 'Compose an epic...', theme: 'snow' }); function modalclick() { $(".dynamic-element").on('click', function(event) { var dataText = JSON.parse($(this).attr('data-text')); $('#exampleModalLong').modal('show'); quill.setContents(dataText); console.log(dataText); }) } $("#addElement").on('click', function(event) { var delta = quill.getContents(); var $_textDelta = JSON.stringify(delta); console.log($_textDelta); $html = "<div class='dynamic-element' data-text='" + $_textDelta + "'>" + "<div>dynamic-element</div>" + "</div>"; $(".element").prepend($html); modalclick(); $('#exampleModalLong').modal('hide'); }) //modalclick(); $("#openmodal").on('click', function(event) { $('#exampleModalLong').modal('show'); }) $('#exampleModalLong').on('hidden.bs.modal', function(e) { quill.deleteText(0, 2000); })
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script> <script src="https://cdn.quilljs.com/1.3.6/quill.min.js"></script> <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/> <link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet"/> <!-- Button trigger modal --> <input type="button" id="openmodal" class="btn btn-info btn-rounded mb-4" value="Add element"> <div class="element"> </div> <!-- Modal --> <div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <div id="editor-container"> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" id="addElement" class="btn btn-primary">Save changes</button> </div> </div> </div> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.