无法将可变数据加载到Summernote中

问题描述 投票:0回答:2

我希望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>

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

javascript php jquery summernote
2个回答
0
投票

您可以通过在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>

0
投票

内容未在代码视图模式下显示。所以,我使用了一个hack - Deactivated codeview并显示内容并重新激活了codeview。以下是适用于我的解决方案。但是,我欢迎任何建议。谢谢,

$(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');
}                

});
© www.soinside.com 2019 - 2024. All rights reserved.