簡體   English   中英

我如何將數據從刀片傳遞到刀片文件

[英]How do i pass data from blade to blade file

單擊按鈕重定向到新窗口后,我嘗試將兩個值從 javascript 傳遞到另一個刀片文件...這是我的代碼

ReportCreate.blade.php js


 $("#state").on("change", function() {
            var id = $(this).val();
            console.log(id)
            var cuid = document.getElementById("cu").value;  
            console.log(cuid)

        });

    </script>


單擊按鈕打開新窗口,其中包含來自 javascript 的兩個值

onclick="openNewWindow('{{ route('sla.slaCategoryTreeListScreen') }}')"

slaCategoryTreeListScreen.blade.php

<!DOCTYPE html>

<script>
// how do i retrieve two value from another blade file
</script>

</html>

首先,您需要在發出請求時發送這些值。 您可以使用查詢參數route()助手上傳遞第二個參數來執行此操作:

onclick="openNewWindow('{{ route('sla.slaCategoryTreeListScreen', ['id' => 123, 'cuid' => 456]) }}')"
                                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

然后,您在控制器中獲取這些值以最終將它們返回到第二個刀片文件:

# MyCoolController.php

public function toMySecondView(Request $request)
{
    $id = $request->get('id');
    $cuid = $request->get('cuid');

    return view('my_cool_second_view', ['id' => $id, 'cuid' => $cuid]);
}

屆時您就可以在第二個視圖中使用它們:

# my_cool_second_view.blade.php

<span> ID: { $id } </span>
<span> CUID: { $cuid } </span>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM