@foreach($data as $row)
@php
App\Http\Livewire\Teamusers::edit($row->id,$row->user_id,$row->team_id);
@endphp
{{--call edit() function from teamusers component--}}
<td class="p-3 px-5"><input type="text" wire:model = "username" class="bg-transparent"></td>
<td class="p-3 px-5"><input type="text" wire:model = "email" value="{{$row->email}}" class="bg-transparent" ></td>
<td class="p-3 px-5">
<select value="team" wire:model = "team" class="bg-transparent" >
@if($row->name == 'Fieldwork')
<option value="1" selected>Fieldwork</option>
<option value="2">Labs</option>
@endif
@if($row->name == 'Labs')
<option value="1" >Fieldwork</option>
<option value="2" selected>Labs</option>
@endif
</select>
</td>
<td class="p-3 px-5">
<select value="role" class="bg-transparent" wire:model = "role">
@if($row->role == 'management')
<option value="management" selected>management</option>
<option value="general">general</option>
@endif
@if($row->role == 'general')
<option value="management" >management</option>
<option value="general" selected>general</option>
@endif
</select>
</td>
<td class="p-3 px-5 flex justify-end">
<button type="button" wire:click="edit({{ $row->id }},{{ $row->user_id }})" class="mr-3 text-sm bg-blue-500 hover:bg-blue-700 text-white py-1 px-2 rounded focus:outline-none focus:shadow-outline">Save</button>
<button type="button" class="text-sm bg-red-500 hover:bg-red-700 text-white py-1 px-2 rounded focus:outline-none focus:shadow-outline">Delete</button>
</td>
</tr>
@endforeachedit.php
public function edit($id,$user_id,$team_id)
{
$user = Teamuser::findOrFail($id);
$real = User::findOrFail($user_id);
$third = Team::findOrFail($team_id);
$this->username = $real->name;
$this->email = $real->email;
$this->team = $third->name;
$this->role = $user->role;
}函数将数据绑定到每个循环中的列。但结果是,它每次都让人耳目一新。

如果我仍然想要数据绑定,但不需要刷新,我该怎么办?
发布于 2022-09-28 08:10:55
您尝试过在livewire模型数据绑定中使用.defer吗?这将使组件不实时,并且只在单击“保存”按钮时提交数据。
对你有帮助吗?
https://stackoverflow.com/questions/73877158
复制相似问题