使用控制器的LiveWire组件编辑用户数据用户数据
我想将ID从标准刀片视图
传递给livewire组件视图
。
我在Blade文件中有一个编辑用户按钮,因此当用户单击按钮Bootstrap Modal
(这是Livewire Component View
),ID将打开。
//一些Ajax用编辑按钮渲染表,
success: function(response) {
$('tbody').html("");
$.each(response, function(key, item) {
str += '<tr>';
//blahh...
str += '<a href="#" id="' + item.id + '" wire:click="edit({{ '+item.id+' }})" class="text-info mx-1 editIcon" data-toggle="modal" data-target="#editUserModal"></a>';
//blahh...
str += '</tr>';
})
$('tbody').append(str);
)};
如果我坚持使用jQuery,我可以成功打开一个使用数据进行编辑的模态。但是我想打开模态作为LiveWire组件。
LiveWire View
<div class="modal fade" id="editUserModal" tabindex="-1" role="dialog" aria-hidden="true">
//blahh
</div>
LiveWire组件
public function render()
{
//some logic here to open modal with id clicked, so I can do something as below
$user = User::where('id', $id)->first();
$this->user_id = $id;
$this->first_name = $student->student_first_name;
return view('livewire.user.edit');
}
任何建议都会有所帮助。 我不想将整个项目移植到Livewire,我只想将LiveWire组件用于某些地方,因为它的简单和较少的代码
I want to pass the id from the standard blade view
to the livewire component view
.
I have an edit user button in the blade file, so when the user clicks on the button bootstrap modal
(which is a livewire component view
) with id will open.
//some ajax to render the table with an edit button
success: function(response) {
$('tbody').html("");
$.each(response, function(key, item) {
str += '<tr>';
//blahh...
str += '<a href="#" id="' + item.id + '" wire:click="edit({{ '+item.id+' }})" class="text-info mx-1 editIcon" data-toggle="modal" data-target="#editUserModal"></a>';
//blahh...
str += '</tr>';
})
$('tbody').append(str);
)};
if I stick to jquery I can successfully open a modal with data to edit. but I want to open the modal as a livewire component.
livewire view
<div class="modal fade" id="editUserModal" tabindex="-1" role="dialog" aria-hidden="true">
//blahh
</div>
livewire component
public function render()
{
//some logic here to open modal with id clicked, so I can do something as below
$user = User::where('id', $id)->first();
$this->user_id = $id;
$this->first_name = $student->student_first_name;
return view('livewire.user.edit');
}
any suggestion will be helpful.
I don't want to port the whole project to livewire I just want to use the livewire component for some places due to its simplicity and lesser code
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以发出事件从表中从表中单击使用
$ emit 或
livewire.emit
。并在您的模态上听:
You can emit an event from the table click using
$emit
orLivewire.emit
.And listen on your modal: