如何将值从视图传递到模态框?

3

我有一个链接,在这个链接上我打开了一个模态框:

<li><a href="#deleteProperty{{$property->id}}" data-toggle="modal"><i class="fa fa-times"></i></a></li>

我有一个在独立页面 modals.blade.php 中的模态框。

<div class="modal fade modal_form" id="deleteProperty{{$property->id}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel5" aria-hidden="true">
              <div class="modal-dialog" role="document">
                  <div class="modal-content">
                      <div class="modal-header">
                          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                              <span aria-hidden="true">&times;</span>
                          </button>
                          <h4 class="modal-title" id="exampleModalLabel5">Are you sure you want to delete this property?</h4>
                      </div>
                      <div class="modal-body">
                      <form method="POST" action="{{ route('user.property.delete',[$user->id,$property->id])}}">
                          <div class="form-group">
                            <div class="left-btn">
                                <button type="button" class="btn btn-primary" data-dismiss="modal">No</button>
                            </div>
                            <div class="right-btn">
                                  <button type="submit" class="btn btn-primary">Yes</button>
                            </div>
                          </div>
                      </form>
                      </div>
                  </div>
              </div>
          </div>

如何将($property->id)参数传递到模态框中,以便用户单击特定属性时删除该属性?


你已经将值传递给了 bootstrap modal。只需要使用 jQuery(?) 访问 .modal div 的 id 属性即可。 - apokryfos
当我传递这个值时,我会得到一个错误:未定义的变量属性。 - None
你是否将属性传递给视图? - apokryfos
是的,我可以在视图中访问属性。 - None
你是如何包含 modals.blade.php 页面的? - apokryfos
我有一个布局,其中使用了 @include('standardUser.includes.modals') 和 @yield('content') 来渲染视图。 - None
1个回答

1
你需要传递想要在包含视图中使用的变量。
例如:
@include('standardUser.includes.modals', [ "property" => $property ]) 

我做不到那个,因为在布局中我没有该属性。 - None
你需要重新思考你的策略。在解决所有属性之后,你需要包含视图,或者你可以使用 View::share('property','$property),但这对你的情况来说只是一种不好的做法。 - apokryfos

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接