2017-08-28 148 views
1

我正在创建一个博客,我想更新一条评论, 我想将评论的当前数据传递给使用TINYMCE所见即所得编辑器的textarea。将数据传递到使用TINYMCE所见即所得模式的textarea内所见即所得

问题是如果我使用tinymce作为textarea,当前数据不会显示在textarea上。

这里是我如何做到这一点

这将触发模式按钮:

<button type="button" class="btn btn-success btn-xs" data-toggle="modal" data-target="#myModal" data-id="{{ $comment->id }}" data-comment=" {{ $comment->comment }}"><i class="fa fa-pencil"></i></button> 

这是模态

<!--UPDATE COMMENT Modal --> 
    <div class="modal fade modal-md" id="myModal" role="dialog"> 
    <div class="modal-dialog"> 

     <!-- Modal content--> 
     <div class="modal-content modal-success"> 
     {{ Form::open(['route' => ['comments.update'], 'method' => 'PUT']) }} 
     <div class="modal-header"> 
      <button type="button" class="close" data-dismiss="modal">&times;</button> 
      <h5 class="modal-title"><b>Update Comment </b></h5> 
     </div> 
     <div class="modal-body"> 
      <div id="comment-form" class=""> 

       <div class="row"> 
        <div class="col-md-12"> 
         {!! Form::hidden('id', '', ['id' => 'comment-id']) !!} 

         {{ Form::textarea('comment', '', ['id'=>'comment-comment','class' => 'form-control', 'rows' => '3']) }} 

        </div> 
       </div> 

      </div> 
     </div> 
     <div class="modal-footer"> 
      <button type="submit" class="btn btn-success"><b>Update</b></button> 
      <button type="button" class="btn btn-default" data-dismiss="modal"> <b>Cancel</b></button> 
     </div> 
     {{ Form::close() }} 
     </div> 
    </div> 
    </div> 

这里是我的JS:

<script type="text/javascript" charset="utf-8"> 

tinymce.init({ 
    selector: 'textarea', 
    menubar: false, 
    toolbar: false, 
    statusbar: false, 
    height:  10 
    }); 

<!--UPDATE COMMENT MODAL--> 
$(function() { 
    $('#myModal').on("show.bs.modal", function (e) { 
     $("#comment-comment").val($(e.relatedTarget).data('comment')); 
     $("#comment-id").val($(e.relatedTarget).data('id')); 
    }); 
}); 

// Prevent bootstrap dialog from blocking focusin 
$(document).on('focusin', function(e) { 
    if ($(e.target).closest(".mce-window").length) { 
     e.stopImmediatePropagation(); 
    } 
}); 

$('#open').click(function() { 
    $("#dialog").dialog({ 
     width: 800, 
     modal: true 
    }); 
}); 

</script> 

回答

0
{!! Form::hidden('id', $data->id , ['id' => 'comment-id']) !!} 

    {{ Form::textarea('comment', $data->coment, ['id'=>'comment-comment','class' => 'form-control', 'rows' => '3']) }} 

如果您使用窗体打开该案例,您需要指定一个值,如“$ data-> coment”。如果您使用Form模型,则不需要指定任何值,只需添加null即可。检查下面的链接。

https://laravel.com/docs/4.2/html#form-model-binding

+0

是它可以,但问题是,它是模态,我想返回到使用文本编辑器的文本区域当前注释的价值,问题是只有一种形式可以被很多评论使用,当前的评论值只需点击编辑按钮即可发送到表单 –