2
在Laravel 5应用程序中,我使用模型来添加项目。在我的视图文件中,我按如下方式执行:Laravel:如何将id传递给模式框进行编辑
<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的建议。我想更新动作URL,所以理想情况下我可以使用JS从该数据项目id中提取值。你碰巧有一些我可以尝试的样本JS代码。恐怕我对JS不是很擅长。 – wiwa1978
@ wiwa1978请检查我的更新回答,请 –
这对于像我这样的JS新手来说相当复杂:-)我最初只将#product-update-form更改为#edit-event-modal(我的模态名)。但是这不起作用....所以(在第2行):我应该给我的模态然后ID =“更新模态”的ID? $(this).data('itemId')是否与我的“data-item-id”相对应。 – wiwa1978