【问题标题】:How to get dynamic data in bootstrap modal for each id by using laravel?如何使用 laravel 在引导模式中为每个 id 获取动态数据?
【发布时间】:2021-01-29 13:11:48
【问题描述】:

我正在开发一个应用程序,该应用程序需要在每次点击我的不同图标列表时显示数据。问题是如何根据 id 在引导模式中显示数据。提前致谢。 index.blade.php .

<div class="col-md-3">
     <button  type="button" class="btn btn-success " data-toggle="modal" data-target="#myModal" data-id="{{$post->id}}">Ajouter
  </button>
 </div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="modelTitleId"
  aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
            <div class="modal-content" >
                <div class="modal-header">
                    <h5 class="modal-title">Modal title</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body" >
                    <div class="container-fluid">
                          <div class="row">
                              <div class="col-md-12 ">
                                 <div class="panel panel-default">
                                    <div class="panel-heading text-center">Nouvelle annonce</div>
                                         <div class=" form-group col-sm-6">
                                            <img class="cart-img img-responsive" src="images/cover_image/{{$post->cover_image}}" alt="IMG-PRODUCT">
                                         </div>
                                        <div class=" form-group col-sm-3">
                                             <span id="layer_cart_product_title" class="product-name layer_cart_product_title"><h2> {{$post->nom_comr}}</h2> </span>
                                                <hr>
                                            <span id="layer_cart_product_ti" class="product-name"><h4> &nbsp;{{$post->date_perm}}</h4> </span>
                                            <span id="layer_cart_product_ti" class="product-name"><h4> &nbsp;{{$post->offre}}</h4> </span>
                                                    <hr>
                                             <span id="layer_cart_product_ti" class="product-name"><h4> &nbsp;{{$post->pv_ht}}</h4> </span>
                                            </div>
                                            

【问题讨论】:

  • 这取决于您的偏好,因为它可以通过多种方式解决,如果您不获取很多项目,例如一次仅 4 或 8 个,您可以预先获取它们。你也可以走ajax路线。将 id 传递给服务器,服务器使用 id 根据 id 进行选择,服务器返回一个包含所有详细信息的 json 字符串,前端接收它,然后将所有内容放入标记中
  • 调用一个函数来获取记录的id并通过Ajax,这样你就可以得到相关id的数据,然后使用JqueryJS绑定到你的模态和打开模态。

标签: javascript php html jquery laravel-5


【解决方案1】:
<button  type="button" class="btn btn-success " data-toggle="modal" data-target="#myModal{{$post->id}}" data-id="{{$post->id}}">Ajouter</button>
<div class="modal fade" id="myModal{{$post->id}}" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">

这对我有用

【讨论】:

  • 我的工作也很棒,感谢 Mitra!
【解决方案2】:

我通过在 data-target 和 midel 中传递帖子 ID 来解决我的问题

    <button  type="button" class="btn btn-success " data-toggle="modal" data-target="#{{$post->id}}">Ajouter </button>

<div class="modal fade" id="{{$post->id}}" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-03
    • 1970-01-01
    • 2018-06-10
    • 2021-07-19
    • 2017-04-21
    • 2017-08-11
    • 2014-10-04
    • 2017-10-14
    相关资源
    最近更新 更多