【问题标题】:How to update the value of nicEdit textarea如何更新 nicEdit textarea 的值
【发布时间】:2016-03-18 23:17:09
【问题描述】:

您好,我有一个表格,其中包含一个帖子列表和每个帖子中的两个按钮(删除和编辑)。所有字段都被编辑,但我无法编辑 nicEdit 文本区域,但是当我尝试编辑第一篇文章的文本区域时,它会被编辑 这是我的 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

【问题讨论】:

  • id 属性必须是唯一的,因此通过 id ("#{{$post-&gt;id}}") 在选择器上调用 each 没有任何意义。向我们展示您的 html。
  • 我得到了我想编辑的帖子的 id {{$post->id}} 它是一个遍历所有帖子的循环
  • @RafałŁużyński 我展示了我的 html 代码,你能帮忙吗!
  • 更好地描述你的问题,我不明白你在做什么。
  • @RafałŁużyński 我正在尝试使用 nicEdit textarea 编辑帖子,但我无法编辑 textarea 的值,我唯一可以编辑的是第一篇帖子中的第一个(因为我有一个包含帖子 ID 的表格标题)。

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


【解决方案1】:

试试这个

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

【讨论】:

    【解决方案2】:

    或者试试这个:

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

    【讨论】:

      猜你喜欢
      • 2013-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多