【问题标题】:why and how to solve 'Uncaught TypeError: Cannot read property 'setData' of undefined' for ckeditor为什么以及如何解决 'Uncaught TypeError: Cannot read property 'setData' of undefined' for ckeditor
【发布时间】:2015-07-29 10:27:03
【问题描述】:

我在引导模式中使用 ckeditor。 ckeditor 中的数据应该在ajax 调用之后动态加载。我无法在 ckeditor 中加载数据。 代码:

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" 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="exampleModalLabel">Thank you Message</h4>
          </div>
          <div class="modal-body">
            <form>
              <div class="form-group">
                <label for="recipient-name" class="control-label">Recipient:</label>
                <input type="text" class="form-control" id="recipient-name">
              </div>
              <div class="form-group">
                <label for="recipient-name" class="control-label">Subject:</label>
                <input type="text" class="form-control" id="subject">
              </div>
              <div class="form-group">
                <label for="message-text" class="control-label">Message:</label>
                <?php $ckeditor->editor('message', '', array('id'=>'editor1')); ?>
              </div>
            </form>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary">Send message</button>
          </div>
        </div>
      </div>
    </div>

脚本

$(document).on('click', '#sendemail', function(){
    var target = $('#hidden_send_email_url').val();
    var id = $(this).find('#hidden_id').val();
    $.ajax({
        url : target,
        data : {id : id},
        type : 'POST',
        dataType: "json",
        success : function(data){
            var modal = $('#exampleModal').modal('show');
            modal.find('.modal-body input#recipient-name').val(data.to)
            modal.find('.modal-body input#subject').val(data.subject)
            CKEDITOR.instances.editor1.setData(data.message)
            
            
        },
        error : function(){
            alert('Error occured');
        }
    })
})

错误是:未捕获的类型错误:无法读取未定义的属性“setData” 如何解决这个问题? 欢迎任何帮助/建议。谢谢。

【问题讨论】:

  • 尝试检查来自console.log(CKEDITOR.instances) 的输出。编辑器尚未实例化,或者它的名称设置为“editor1”以外的其他名称
  • @mark.monteiro 谢谢解决问题。
  • 在哪里可以查看编辑者姓名

标签: javascript jquery twitter-bootstrap ckeditor


【解决方案1】:

我刚刚通过从textarea 中删除id 属性解决了这个问题

【讨论】:

    猜你喜欢
    • 2020-10-29
    • 2017-04-24
    • 2022-10-18
    • 1970-01-01
    • 1970-01-01
    • 2013-01-15
    • 2020-05-10
    • 2019-01-21
    • 2019-02-12
    相关资源
    最近更新 更多