Summernote 0.8.20 问题 html 文本播种 - 第二次触发 js/jquery 代码时发生错误

发布于 2025-01-11 22:51:56 字数 5495 浏览 3 评论 0原文

我正在使用 Summernote 0.8.20,并尝试根据表字段的选择填充种子文本(即,种子文本根据所选的表单元格而变化)。当我第一次选择触发表单元格(即满足条件的单元格)时,它会起作用。第二次不显示种子文本,并且出现控制台错误:

summernote-bs4.min.js:2 Uncaught TypeError: Cannot read properties of null (reading 'appendChild')

该错误是由以下行引起的:

if ($.inArray(currentColumn, assistArray) > -1) {
    $('#ymSpecificLine').summernote('pasteHTML', '<p><b>How were you involved in reviewing?</b><br><br></p> <p><b>How did you assist?</b><br><br></p> <p><b>How were you involved in planning?</b><br><br></p> <p><b>My role was (what did you do):</b><br><br></p>');
 }else {
     $('#ymSpecificLine').summernote('pasteHTML', '<p><b>How were you involved in reviewing?</b><br><br></p> <p><b>How did you lead?</b><br><br></p> <p><b>How were you involved in planning?</b><br><br></p> <p><b>My role was (what did you do):</b><br><br></p>');
 }

我知道这一点,因为当我将它们注释掉时,不会发生错误。

HTML:

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Assist/Lead Details</h4>
      </div>
      <div class="modal-body">
        <!-- Summernote input area -->
        <div class="row">
            <div class="container-fluid">
                <div id='ymSpecific' class="row">
                    <div class="container-fluid">
                        <div class="input-group">
                            <label for="ymSpecificLine" class="text-left col-lg-12 col-md-12 col-sm-12 col-xs-12 col-form-label">You may enter specific information relating to you Assist or Lead:</label>
                            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 text-left">
                                <textarea class="summernote col-lg-12 col-md-12 col-sm-12 col-xs-12" id="ymSpecificLine" name="ymSpecificLine" rows="20"></textarea>
                            </div>
                        </div>
                    </div><!-- /container -->
                </div><!-- /row -->
            </div><!-- /container -->
        </div><!-- /row -->
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Clear</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

JS:

var leadArray = [8, 16, 24, 32, 44, 52, 60, 68, 80, 81, 82, 83, 91, 92, 93, 94,
                 102, 103, 104, 105, 113, 114, 115, 116];

var assistArray = [7, 15, 23, 31, 42, 43, 50, 51, 58, 59, 66, 67, 77, 78, 79, 88, 89, 90,
             99, 100, 101, 110, 111, 112];

$("#ymSpecificLine").summernote('code', '');
var currentColumn = parseInt(sel.dataset.column, 10);

//Check if Assist or Lead (requires details to be entered)
alert("New currentColumn: " + currentColumn);
if ($.inArray(currentColumn, assistArray) > -1 || $.inArray(currentColumn, leadArray) > -1){

    $('.summernote').summernote({
        toolbar: [
           // [groupName, [list of button]]
           ['style', ['bold', 'italic', 'underline', 'clear']],
           ['font', ['strikethrough']],
           ['fontsize', ['fontsize']],
           ['color', ['color']],
           ['para', ['ul', 'ol', 'paragraph']],
           ['height', ['height']]
        ]
    });
    
    $("#myModal").modal('show');
    
    if ($.inArray(currentColumn, assistArray) > -1) {
        $('#ymSpecificLine').summernote('pasteHTML', '<p><b>How were you involved in reviewing?</b><br><br></p> <p><b>How did you assist?</b><br><br></p> <p><b>How were you involved in planning?</b><br><br></p> <p><b>My role was (what did you do):</b><br><br></p>');
    }else {
        $('#ymSpecificLine').summernote('pasteHTML', '<p><b>How were you involved in reviewing?</b><br><br></p> <p><b>How did you lead?</b><br><br></p> <p><b>How were you involved in planning?</b><br><br></p> <p><b>My role was (what did you do):</b><br><br></p>');
    }
}

第一次选择的结果:

在此处输入图像描述

第二次选择的结果:

在此处输入图像描述

I am using Summernote 0.8.20 and am trying to populate with seed text depending on the selection of a table field (i.e., the seed text changes depending on the table cell selected). The first time I select a triggering table cell (i.e., one that meets the criteria) it works. The second time the seed text is not displayed and there is a console error:

summernote-bs4.min.js:2 Uncaught TypeError: Cannot read properties of null (reading 'appendChild')

The error is caused by the lines:

if ($.inArray(currentColumn, assistArray) > -1) {
    $('#ymSpecificLine').summernote('pasteHTML', '<p><b>How were you involved in reviewing?</b><br><br></p> <p><b>How did you assist?</b><br><br></p> <p><b>How were you involved in planning?</b><br><br></p> <p><b>My role was (what did you do):</b><br><br></p>');
 }else {
     $('#ymSpecificLine').summernote('pasteHTML', '<p><b>How were you involved in reviewing?</b><br><br></p> <p><b>How did you lead?</b><br><br></p> <p><b>How were you involved in planning?</b><br><br></p> <p><b>My role was (what did you do):</b><br><br></p>');
 }

I know this because when I comment them out the error does not occur.

The HTML:

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
        <h4 class="modal-title" id="myModalLabel">Assist/Lead Details</h4>
      </div>
      <div class="modal-body">
        <!-- Summernote input area -->
        <div class="row">
            <div class="container-fluid">
                <div id='ymSpecific' class="row">
                    <div class="container-fluid">
                        <div class="input-group">
                            <label for="ymSpecificLine" class="text-left col-lg-12 col-md-12 col-sm-12 col-xs-12 col-form-label">You may enter specific information relating to you Assist or Lead:</label>
                            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 text-left">
                                <textarea class="summernote col-lg-12 col-md-12 col-sm-12 col-xs-12" id="ymSpecificLine" name="ymSpecificLine" rows="20"></textarea>
                            </div>
                        </div>
                    </div><!-- /container -->
                </div><!-- /row -->
            </div><!-- /container -->
        </div><!-- /row -->
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Clear</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

The JS:

var leadArray = [8, 16, 24, 32, 44, 52, 60, 68, 80, 81, 82, 83, 91, 92, 93, 94,
                 102, 103, 104, 105, 113, 114, 115, 116];

var assistArray = [7, 15, 23, 31, 42, 43, 50, 51, 58, 59, 66, 67, 77, 78, 79, 88, 89, 90,
             99, 100, 101, 110, 111, 112];

$("#ymSpecificLine").summernote('code', '');
var currentColumn = parseInt(sel.dataset.column, 10);

//Check if Assist or Lead (requires details to be entered)
alert("New currentColumn: " + currentColumn);
if ($.inArray(currentColumn, assistArray) > -1 || $.inArray(currentColumn, leadArray) > -1){

    $('.summernote').summernote({
        toolbar: [
           // [groupName, [list of button]]
           ['style', ['bold', 'italic', 'underline', 'clear']],
           ['font', ['strikethrough']],
           ['fontsize', ['fontsize']],
           ['color', ['color']],
           ['para', ['ul', 'ol', 'paragraph']],
           ['height', ['height']]
        ]
    });
    
    $("#myModal").modal('show');
    
    if ($.inArray(currentColumn, assistArray) > -1) {
        $('#ymSpecificLine').summernote('pasteHTML', '<p><b>How were you involved in reviewing?</b><br><br></p> <p><b>How did you assist?</b><br><br></p> <p><b>How were you involved in planning?</b><br><br></p> <p><b>My role was (what did you do):</b><br><br></p>');
    }else {
        $('#ymSpecificLine').summernote('pasteHTML', '<p><b>How were you involved in reviewing?</b><br><br></p> <p><b>How did you lead?</b><br><br></p> <p><b>How were you involved in planning?</b><br><br></p> <p><b>My role was (what did you do):</b><br><br></p>');
    }
}

The result on first select:

enter image description here

The result on second select:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尹雨沫 2025-01-18 22:51:56

我通过注释发现:

$("#ymSpecificLine").summernote('code', '');

控制台错误没有发生;但是,在每个页面重新加载时,种子文本都会重复。这就是为什么这条线首先存在的原因。我发现:

$("#ymSpecificLine").summernote('reset');

这不会导致我收到控制台消息,并且每次重新加载时种子行都不会重复。但是,这也消除了调整文本区域大小的能力。

有没有办法在重置后启用调整大小?

I discovered that by commenting out:

$("#ymSpecificLine").summernote('code', '');

The console error did not occur; however, on each page reload the seed text was duplicated. Which is why that line was there for in the first place. I found:

$("#ymSpecificLine").summernote('reset');

This does not result in me getting the console message and the seed lines are not duplicated with each reload. However, this also removes the ability to resize the text area.

Is there a way to enable the resize after a reset?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文