将数据传递到模态时出现重复的 CKEditor5 问题

Problem with duplicate CKEditor5 when passing data into Modal

提问人:Khang Khang 提问时间:10/12/2023 最后编辑:Khang Khang 更新时间:10/12/2023 访问量:42

问:

我使用 AJAX 请求从数据库中获取数据。当我将每个数据传递到输入表单中时,没关系,但是当我将数据传输到 CKEditor5 时,我收到一个错误:每次我关闭并重新打开模态时,模态都会出现。传递给 CKEditor 的数据不会更改,但会创建一个新的 CKEditor。这是我的 Modal 和 AJAX 请求代码

<div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="detailModal"
        aria-hidden="true" id="detailPlaceModal">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">

                <div class="modal-header">
                    <h5 class="modal-title h4" id="detailModal">Detail Place</h5>
                    <button type="button" class="btn btn-xs btn-icon btn-ghost-secondary" data-dismiss="modal"
                        aria-label="Close">
                        <i class="tio-clear tio-lg"></i>
                    </button>
                </div>
                <div class="modal-body">
                    <div id="detailContent">
                            <div class="form-group">
                                <label for="describe_place">Mô tả</label>
                                <textarea id="editCKeditor" class="form-control" name="describe_view_place"></textarea>
                            </div>
                            <div class="form-group">
                                <button data-modal-hide="defaultModal" type="submit" class="btn btn-primary">I
                                    accept</button>
                            </div>
                    </div>

                </div>
            </div>
        </div>
</div>

阿贾克斯

function getDetailPlace(event, element) {
            event.preventDefault();
            var url = $(element).attr('href');

            $.ajax({
                url: url,
                type: 'GET',
                success: function(response) {
                    var detailData = response.vlplace[0];  
                    $('#describe_view_place').val(detailData.describe_place);
                    ClassicEditor
                        .create(document.querySelector('#editCKeditor'))
                        .then(editor => {
                            var describeValue = detailData.describe_place;
                            editor.setData(describeValue);
                        })
                        .catch(error => {
                            console.error(error);
                        });
                    $('#detailPlaceModal').modal('show');
                },
                error: function() {

                }
            });
}

我研究并修复了它,但无能为力

php ajax laravel bootstrap-modal ckeditor5

评论


答:

0赞 khush 10/12/2023 #1

在 AJAX 中

var myEditorSend;
function getDetailPlace(event, element) {
        event.preventDefault();
        var url = $(element).attr('href');
        editCKeditor();
        myEditorSend.setData('');
        $.ajax({
            url: url,
            type: 'GET',
            success: function(response) {
                var detailData = response.vlplace[0];  
                $('#describe_view_place').val(detailData.describe_place);
                var describeValue = detailData.describe_place;
                myEditorSend.setData(describeValue);
                $('#detailPlaceModal').modal('show');
            },
            error: function() {

            }
        });
      }
      var editCKeditor= () => {
       ClassicEditor
        .create(document.querySelector('#editCKeditor'))
        .then(editor => {
          myEditorSend = editor;
        // console.log(editor);
      })
     .catch(error => {
       console.error(error);
     });
    }

评论

0赞 Khang Khang 10/12/2023
我试图修复它,但它没有用,在创建新的 ckeditor 时它仍然不断重复
0赞 Khang Khang 10/12/2023
我修复了它,我为另一个函数创建了ajax,并调用它来将数据导入类编辑器的.then