如何更新nicEdit textarea的值

时间:2015-12-13 11:43:20

标签: javascript jquery laravel-5 nicedit laravel-blade

您好我有一个表格包含帖子列表和每个帖子中的两个按钮(删除和编辑)。所有字段都被编辑但我无法编辑nicEdit textarea但是当我尝试编辑第一篇文章的textarea时它会被编辑 这是我的jquery代码:

 <script type="text/javascript">
   $(function() {
     $("#myForm").submit(function() {
       $("textarea").each(function(){ 
         new nicEditors.findEditor(this.id).saveContent();
       });
     });
   });
</script>

这是我的观点:

         @foreach($articles as $post)

            <tr>

            <td>{{$post->title}}</td>
            <td>{{$post->published_at}}</td>
            <td><p data-placement="top" data-toggle="tooltip" title="Edit"><button class="btn btn-primary btn-xs" data-title="Edit" data-toggle="modal" data-target="#edit{{$post->id}}" ><span class="fa fa-pencil"></span></button></p></a></td></a>
            <td><p data-placement="top" data-toggle="tooltip" title="Delete"><button class="btn btn-danger btn-xs" data-title="Delete" data-toggle="modal" data-target="#delete{{$post->id}}" ><span class="fa fa-trash"></span></button></p></td>
        <div class="modal fade" id="edit{{$post->id}}" tabindex="-1" role="dialog" aria-labelledby="edit" aria-hidden="true">
              <div class="modal-dialog">
            <div class="modal-content">
                  <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
                <h4 class="modal-title custom_align" id="Heading">Edit l'article : {{$post->id}}</h4>
              </div>    
              <div class="modal-body"> 
                          {!! Form::model($post,['method' => 'PATCH','files'=> true,'id'=>'myForm','route' => ['articles.update', $post->id]])!!}

        @include('partials.postForm')

        </div>
</tr> 

    @endforeach

2 个答案:

答案 0 :(得分:2)

试试这个

$("#myForm").submit(function() {
   $("textarea").each(function(){ 
     $(this).val($(this).closest('tr').find('.nicEdit-main').html());
   });
 });

答案 1 :(得分:0)

或者试试这个:

$('.nicEdit-main').html(/*updated content*/);