【问题标题】:Laravel data with Modal带有模态的 Laravel 数据
【发布时间】:2018-11-21 13:28:18
【问题描述】:

我正在使用 Laravel 和 mysql。我正在尝试创建一个视图,在引导模式中单独显示我的每一行数据

我在每一行都有自己的特定列中放置了一个触发按钮 但我的问题是,我为每一行获取了表(数据库中)最后一行的数据(我的意思是即使我点击第二行按钮,相同的数据也会在我的模式上重复自身)。

这是我的模态:

<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalCenterTitle">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="table-responsive">
          <div hidden class=" tablesaw-bar tablesaw-mode-stack"></div>
        <table border="1px"class="tablesaw tablesaw-stack" data-tablesaw-mode="stack">
          <head>
          <tr>

            <th>User name</th>

          </tr>
        </head>
        <body>

          <tr>

            <td>{{$user->name}}</td>
          </tr>

        </body>
        </table>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

这是我的按钮

<td>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
Show data
 </button>
</td>

已解决

感谢 Jeff 提到的解决方案是使用我的对象的 id 我不知道如何解释但我已将模态放入我的元素中,因此它现在可以按照 Jeff 的解决方案工作。

@foreach($sujets as $sujet)
        <tr>
          <td>{{$sujet->nomsujet}}</td>
          <td>
          <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter{{$sujet->id}}">
          show data
          </button>
          <!-- Modal -->
          <div class="modal fade" id="exampleModalCenter{{$sujet->id}}"  tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered" role="document">
              <div class="modal-content">
                <div class="modal-header">
                  <h5 class="modal-title" id="exampleModalCenterTitle">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="table-responsive">
                    <div hidden class=" tablesaw-bar tablesaw-mode-stack"></div>
                  <table border="1px"class="tablesaw tablesaw-stack" data-tablesaw-mode="stack">
                    <head>
                   <tr>
                      <th>Date </th>                       
                    </tr>
                  </head>
                  <body>

                    <tr>
                      <td>{{$sujet->date}}</td>                         
                    </tr>

                  </body>
                  </table>
                </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                </div>
              </div>
            </div>
          </div>

          </td>

        </tr>
        @endforeach

【问题讨论】:

  • 请将您的解决方案转移到自己的答案中,谢谢。

标签: laravel modal-dialog


【解决方案1】:

每行的模态 ID 必须是唯一的。在您的模态代码中,它可以标记为id="exampleModalCenter{{$user-&gt;id}}"

那么你的按钮就是data-target="#exampleModalCenter{{$user-&gt;id}}"

【讨论】:

  • 谢谢我跟着你的 solotion 现在只有最后一个按钮在工作
  • 你是打印一次模态吗?您需要每一行的模式代码。你可以把它放在按钮旁边
  • 哦,我搞砸了,谢谢,我只需要将模型放在一个元素中,这样我就可以拥有许多模态而不是只有一个,现在它工作得很好
  • 谢谢杰夫,它正在工作我已经编辑了我的帖子,以便人们可以在需要时找到解决方案
【解决方案2】:

如果每个按钮都引用同一个模态,则每次按下按钮时都会看到相同的模态。你能确认你有多个按钮,每个按钮都指向同一个模式(#exampleModalCenter)吗?如果是这样,我可以从那里提供帮助。

【讨论】:

  • 好的。您能否分享根据您的数据库返回的数据生成按钮的代码?
  • 你好尼克我已经分享了我编辑问题的代码并解决了问题谢谢
猜你喜欢
  • 1970-01-01
  • 2022-01-07
  • 1970-01-01
  • 2015-10-12
  • 1970-01-01
  • 2016-02-16
  • 2016-12-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多