【问题标题】:Cannot load variable data into Summernote无法将可变数据加载到 Summernote
【发布时间】:2023-03-18 22:13:01
【问题描述】:

如果加载时存在,我希望 Summernote 显示内容。但是在代码视图中初始化期间,我无法将变量的值加载到 Summernote 中。

代码如下:

$(document).ready(function() {                
    $('.summernote').on('summernote.init', function () {
      $('.summernote').summernote('codeview.activate');
    }).summernote({
      height: 300,
      placeholder: 'Paste content here...',
      codemirror: { 
        theme: 'monokai'
      }
    }).summernote('code', '<?php echo isset($profiledata["Profile"])?$profiledata["Profile"]:"" ?>');

});

<form>
<div class="form-group">
   <label for="summernote"><strong>Paste the HTML code here:</strong></label>        
   <textarea class="summernote" name="profile" id="profile"> </textarea>        
</div>
<button type="submit" class="btn btn-success" id="submitButton">Submit</button>
</form>

我发布了适合我的解决方案。但是,我欢迎任何建议。谢谢,

【问题讨论】:

  • 这个问题和 PHP 有什么关系?
  • 在 textarea 中添加 data-plugin="summernote"
  • @MagnusEriksson 问题已编辑。
  • @NimsPatel 试过了。不工作

标签: javascript php jquery summernote


【解决方案1】:

你可以通过在textarea标签之间设置来获取Summernote中已有的内容。

<form>
<div class="form-group">
<label for="summernote"><strong>Paste the HTML code here:</strong></label>        
<textarea class="summernote" name="profile" id="profile"><?php echo 
((isset($yourcontent)) ? '' . $yourcontent . '' : ''); ?></textarea>        
</div>
<button type="submit" class="btn btn-success" 
id="submitButton">Submit</button>
</form>

【讨论】:

  • 谢谢。但这只是显示内容。文本区域消失了。
【解决方案2】:

内容未在 codeview 模式下显示。因此,我使用了 hack - 停用代码视图并显示内容并重新激活代码视图。这是对我有用的解决方案。但是,我欢迎任何建议。谢谢,

$(document).ready(function() {                

    $('.summernote').on('summernote.init', function () {
      $('.summernote').summernote('codeview.activate');
    });

    $('#profile').summernote({
      height: 300,
      placeholder: 'Paste content here...',
      codemirror: { 
        theme: 'monokai'
      }
    });

    codeviewOn = $('#profile').summernote('codeview.isActivated');        
    if (codeviewOn) {
  $('.summernote').summernote('codeview.deactivate');
  $('#profile').summernote('code', '<?php echo json_encode($profiledata["Profile"]);?>');
  $('.summernote').summernote('codeview.activate');
}                

});

【讨论】:

    猜你喜欢
    • 2014-09-03
    • 2013-07-25
    • 1970-01-01
    • 2018-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多