亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 179 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號