Laravel 将旧值或值传递给模态

看起来 Modal 不太容易大规模实现,我想找到一种替代方法将值传递给模态以便正确显示它。


在下面的示例中,我从数据表本身填充“名称”字段,这很好用,但是如果我想传递,该怎么办


old('name') ?? $document->name

我怎样才能大规模地完成这个任务,比如 10 个以上的字段条目?


按钮


<a href="#"><i class="bx bxs-edit text-primary bx-sm edit" title="Edit Document"></i></a>

脚本


<script type="text/javascript">

$(document).ready( function () {

    var table = $('#indextable').DataTable();

    

    //Edit Record

    table.on('click', '.edit', function(){

       $tr = $(this).closest('tr');

       if ($($tr).hasClass('child')){

           $tr = $tr.prev('.parent');

       }

        //Config Table

        var data = table.row($tr).data();

        $('#name').val(data[1]);

        

        $('#editForm').attr('action', '/virtual/documents/'+data[0]);

        $('#editModal').modal('show');

    });

    

    $("#editForm").submit(function () {

        $(".submit").attr("disabled", true);

            return true;

    });

});


@if (count($errors) > 0)

    $('#editModal').modal('show');

@endif

</script>


冉冉说
浏览 98回答 2
2回答

天涯尽头无女友

这是有意义的解决方案。步骤1)在按钮中添加数据-###,并且它必须位于指定标题之前。<a href="#"><i class="bx bxs-edit text-primary bx-sm edit" data-name="{{old('name') ?? $document->name}} " title="Edit Document"></i></a>步骤2)在脚本中,您可以使用示例“$(this).data('name');”来获取数据<script type="text/javascript">$(document).ready( function () {&nbsp; &nbsp; //Getting the datatable ready&nbsp; &nbsp; var table = $('#indextable').DataTable();&nbsp; &nbsp; //if the edit button is clicked&nbsp; &nbsp; table.on('click', '.edit', function(){&nbsp; &nbsp; &nbsp; &nbsp; var nameData = $(this).data('name');&nbsp; &nbsp; &nbsp; &nbsp; $("#name").val(nameData);&nbsp; &nbsp; &nbsp; &nbsp; $('#editModal').modal('show');&nbsp; &nbsp; });});//On error keep the modal open@if (count($errors) > 0)&nbsp; &nbsp; $('#editModal').modal('show');@endif</script>

慕虎7371278

例如,另一种选择是重新刷新会话;//On error keep the modal open@if (count($errors) > 0)&nbsp; &nbsp; {{ Session::reflash()}}&nbsp; &nbsp; $('#editModal').modal('show');@endifold('value')然后您可以在模态视图中使用标准语法。
打开App,查看更多内容
随时随地看视频慕课网APP