为了账号安全,请及时绑定邮箱和手机立即绑定

Laravel 将旧值或值传递给模态

Laravel 将旧值或值传递给模态

PHP
冉冉说 2023-07-08 16:38:52
看起来 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>
查看完整描述

2 回答

?
天涯尽头无女友

TA贡献1831条经验 获得超9个赞

这是有意义的解决方案。


步骤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 () {

    //Getting the datatable ready

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

    //if the edit button is clicked

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

        var nameData = $(this).data('name');

        $("#name").val(nameData);

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

    });

});

//On error keep the modal open

@if (count($errors) > 0)

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

@endif

</script>


查看完整回答
反对 回复 2023-07-08
?
慕虎7371278

TA贡献1802条经验 获得超4个赞

例如,另一种选择是重新刷新会话;


//On error keep the modal open

@if (count($errors) > 0)

    {{ Session::reflash()}}

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

@endif

old('value')然后您可以在模态视图中使用标准语法。


查看完整回答
反对 回复 2023-07-08
  • 2 回答
  • 0 关注
  • 95 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信