所以我有这个代码,第一个select的getCustomers方法工作正常-第二个似乎根本没有启动,它甚至没有在方法开始时击中dd,我不知道为什么
Livewire代码
public function getCustomers($PartnerId)
{
$team = Team::where('id', $PartnerId)->where('type', '=', 'Partner')->first();
$this->customers = Team::where('team_id', $team->id)->where('type', '=', 'Customer')->get();
}
public function getProjects($customerId){
$this->projects = Project::where('team_id', $customerId)->get();
}
叶片模板
<div class="col-span-4 sm:col-span-4">
<x-jet-label for="type" value="{{ __('Partner') }}" />
<x-select name="selectedPartner" wire:model="selectedPartner" wire:change="getCustomers(selectedPartner)">
<x-select-option :value="null">Select Option</x-select-option>
@foreach($partners as $option)
<x-select-option :value="$option->id" wire:key="{{$option->id}}">{{ $option->name }}</x-select-option>
@endforeach
</x-select>
</div>
<div class="col-span-4 sm:col-span-4">
<x-jet-label for="type" value="{{ __('Customer') }}" />
<x-select name="selectedCustomer" wire:model="selectedCustomer" wire:change="getProjects(selectedCustomer)">
<x-select-option :value="null">Select Option</x-select-option>
@foreach($customers as $option)
<x-select-option :value="$option->id" wire:key="{{$option->id}}">{{ $option->name }}</x-select-option>
@endforeach
</x-select>
</div>
通过将每个元素 Package 在它们自己的div标记中解决了这个问题,如下所示
<div class="col-span-6 sm:col-span-6">
<div >
<x-jet-label for="type" value="{{ __('Partner') }}" />
<x-select name="selectedPartner" wire:model="selectedPartner" wire:change="getCustomers($event.target.value)">
<x-select-option :value="null">Select Option</x-select-option>
@foreach($partners as $option)
<x-select-option :value="$option->id" wire:key="{{$option->id}}">{{ $option->name }}</x-select-option>
@endforeach
</x-select>
</div>
</div>
<div class="col-span-6 sm:col-span-6">
<div>
<x-jet-label for="type" value="{{ __('Customer') }}" />
<x-select name="selectedCustomer" wire:model="selectedCustomer" wire:change="getProjects($event.target.value)">
<x-select-option :value="null">Select Option</x-select-option>
@foreach($customers as $option)
<x-select-option :value="$option->id" wire:key="{{$option->id}}">{{ $option->name }}</x-select-option>
@endforeach
</x-select>
</div>
</div>
1条答案
按热度按时间dphi5xsq1#
在wire:key中为每个选择添加不同的前缀,因为来自不同模型的相同 id 会导致冲突:wire:key 在页面上必须是唯一的
参考