【问题标题】:Laravel: how to pass id to a modal for editingLaravel:如何将 id 传递给模态进行编辑
【发布时间】:2022-11-24 23:19:50
【问题描述】:

在 Laravel 8 应用程序中,我使用模型来添加项目。在我的视图文件中,我这样做如下

<a href="#" data-toggle="modal" data-target="#add-item-modal" type="button" class="btn btn-sm btn-primary btn-create"> Create new item</a>

<div class="modal fade" id="add-item-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
    <div class="modal-dialog">
      <div class="loginmodal-container">
        .... <form comes here>
      </div>
    </div>
</div>

如前所述,这适用于添加项目。

我现在也想使用类似的逻辑来编辑项目。所以我在我的页面上添加了以下内容

<a href="#" data-toggle="modal" data-target="#edit-auction-modal" type="button" class="btn btn-sm btn-primary btn-warning"><em class="fa fa-pencil"></em></a>

<div class="modal fade" id="add-item-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
    <div class="modal-dialog">
      <div class="loginmodal-container">
        .... <form comes here>
      </div>
    </div>
</div>

然而,问题是我需要将当前项目(我希望编辑)的 id 传递给模式框,以便模式可以显示我希望更新的项目的值。

如何才能做到这一点?

【问题讨论】:

  • 你的模式的id属性不适合data-target

标签: javascript html laravel-8


【解决方案1】:

检查此链接Bootstrap 5.2 Modal

【讨论】:

  • 欢迎。请不要仅发布链接答案。如果您发布的 URL 无法访问,则此答案毫无价值。添加代码
  • 你好,这是指向 bootstrap 官方文档的链接,其中显示了如何使用具有动态值的模态。
猜你喜欢
  • 1970-01-01
  • 2019-04-03
  • 2020-05-25
  • 1970-01-01
  • 1970-01-01
  • 2021-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多