【发布时间】:2022-01-01 01:50:54
【问题描述】:
我是使用 laravel 刀片模板的新手。
我有一个引导模式,需要在按钮单击时显示,此外,我需要在该单击事件上传递一些值。
例如。
在我的父刀片上:(顺便说一句,它是一个嵌套的模态刀片)
modal_1.blade.php
<div class="modal" id="modal1">
...
@foreach($templates as $key => $val)
<button onclick="previewItem($templates[$key]['color'])">
</button>
@endforeach
</div>
<script>
const previewItem = (color) => {
// how to pass this `color` to the child modal blade
}
</script>
和子刀片模态
modal_2.blade.php
<div class="modal" id="modal2">
// how to access passed variable from modal1 ?
</div>
【问题讨论】:
-
我没有看到您在 modal1 文件中包含 modal2 文件的位置。您缺少
@include或者您没有真正将 modal_2 嵌入到 modal_1 中。变量通过@include()传递。 -
@DanielW.,我把它放在
modal1里面。但是,我认为我可以在 php 中使用该 javascript 变量。 -
HTML 中的变量可以在下一个请求时传递(ajax、带有 post 的表单、链接或带有 get 的表单)。
-
您是否查看了源代码以确保一切正常。我假设
<button onclick="previewItem($templates[$key]['color'])">应该是<button onclick="previewItem('{{$templates[$key]['color'])}}'">, since it's Blade. And'` 因为它应该是一个 JS 字符串
标签: laravel laravel-blade