当前位置: 首页 > 知识库问答 >
问题:

每行带有编辑模式的Laravel表

松灿
2023-03-14

我想在每一行中制作一个带有编辑按钮的表格。编辑按钮将呈现带有该行加载数据的模态弹出窗口。

这是我的刀。php

<div class="card-body">       
    @foreach($employee_education as $employee_education)
        <div class="card card-primary card-outline">
            <div class="card-header bg-white">
                <h5 class="card-title m-0">
                    {{ $employee_education->degree_title }}
                </h5>
                <a 
                    href="#" 
                    data-toggle="modal" 
                    id="education_edit_link" 
                    data-target="#education_edit_modal" 
                    class="btn  btn-primary btn-xs" 
                    style="float:right;color:white!important;"
                >
                    <i class="fas fa-edit"></i> Edit
                </a>
            </div>
            <div class="card-body bg-light">
                <table class="table table-hover table-sm  table-borderless">
                    <tbody>
                        <tr>
                            <th>Degree Title</th>
                            <td>{{$employee_education->degree_title}}   </td>
                        </tr>
                        <tr>
                            <th>Institute</th>
                            <td>{{$employee_education->institute}}  </td>
                        </tr>
                        <tr>
                            <th>Address </th>
                            <td>{{$employee_education->address}}    </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>

        <!-- Modal -->
        <div 
            class="modal fade" 
            id="education_edit_modal" 
            tabindex="-1" 
            role="dialog" 
            aria-labelledby="connection_detailsLabel" 
            aria-hidden="true"
        >
           <div class="modal-dialog modal-lg" role="document">
                <div class="modal-content">
                    <div class="modal-body">
                        <div class="card-body">
                            <table class="table table-hover table-sm  table-borderless">
                                <tbody>
                                    <tr>
                                        <th>Degree Title</th>
                                        <td>{{$employee_education->degree_title}}   </td>
                                    </tr>
                                    <tr>
                                        <th>Institute</th>
                                        <td>{{$employee_education->institute}}  </td>
                                    </tr>
                                    <tr>
                                        <th>Address </th>
                                        <td>{{$employee_education->address}}    </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="button" type="submit" id="btn_update" class="btn btn-primary">Send</button>
                </div>
            </div>
        </div>
    </div>
    <!-- Modal End -->    
@endforeach

但该模型每次仅显示第一行数据。如何获取已单击行的数据加载到模式中

共有2个答案

沈博涉
2023-03-14

原因

如果您检查DOM,您会发现您有多个模态,因为它每次循环通过$employee_education集合时都会呈现一个模态。

这些模式中的每一个都将具有相同的id属性,因为您在循环中不改变这个属性(即每个模式的id都是education\u edit\u modal)。

由于id应该是唯一的,它将在第一次找到具有id的元素后停止查找。这就是为什么它总是包含循环中第一个对象的内容。

解决方案

  1. 尝试在循环外部渲染单个模式,并使用属性传递数据。这更高效,并且不需要进行某种动态id生成

https://getbootstrap.com/docs/4.0/components/modal/#varying-modal-content

夏侯承恩
2023-03-14

发生这种情况是因为您的所有情态动词都具有相同的id。

您可以轻松地将employee_education的id添加为模式的id:

  1. 您需要调整切换链接,添加employee_education-
<a href="#" data-toggle="modal" id="education_edit_link" 
data-target="#education_edit_modal{{$employee_education->id}}"...
<div class="modal fade" id="education_edit_modal{{$employee_education->id}}" 
        ... >

请注意:您正在foreach循环中使用$employee\u education作为$employee\u education。您可能需要重命名变量,因为它们的名称相同。

 类似资料:
  • class BaseDatabaseSchemaEditor[source] Django的迁移系统分为两个部分;计算和储存应该执行什么操作的逻辑 (django.db.migrations) ,以及用于把“创建模型”或者“删除字段”变成SQL语句的数据库抽象层 -- 后者是模式编辑器的功能。 你可能并不想像一个普通的开发者使用Django那样,直接和模型编辑器进行交互,但是如果你编写自己的迁移系

  • 我想定制一个EditText,它应该像下图中那样具有“常量”,这样我就可以得到分钟和秒。(数字接口无关)。

  • 我不知道发生了什么,但我正在Windows中的VSCODE工作,将neovim路径添加到settings.json. 我在设置中单击。json和vscode开始自己打开新的编辑器选项卡,其内容与settings.json相同。 我卸载了几次vscode,删除了Appdata漫游vscode、Appdata本地代码等。我重新启动了我的windows机器,并采取了同样的行为。 同步已打开,因此设置将复

  • 在IntelliJ中,我们可以使用Alt Shift Insert在每行的同一位置进行多行编辑。当每行的长度不同时,我们可以在每行的末尾进行多行编辑吗?使用场景是在每行末尾编辑分号。 谢谢。

  • MATLAB的figure窗口支持一种指向和点击方式的编辑模式,用它可以自定义图形的外观。以下插图说明打开了作图编辑模式的figure窗口及标明了此模式的主要特点。

  • 很多天来,我一直试图在FlexGrid中实现模态对话框编辑,但都没有成功。 我从一个非常简单的例子开始: http://mvc4beginner.com/Sample-Code/Insert-Update-Delete/Asp-.Net-MVC-Ajax-Insert-Update-Delete-Using-Flexigrid.html 我对这个示例进行了很多扩展,但遇到了一个障碍,我不知道如何实