select
每次更改以前的输入时,我都尝试添加新输入select
,但是当我尝试将更多元素添加到组件类的公共属性时,出现错误:
Livewire 在尝试对 [product-categories] 组件进行水合时遇到损坏的数据。确保 Livewire 组件的 [name, id, data] 在请求之间没有被篡改。
班上
class Category extends Component {
public array $categories = [];
public function edit($category) {
$this->state = $category;
$this->categories[] = []; // more info from an api
}
public function choose($category) {
$this->categories[] = []; // more info from an api
}
}
模板:
@if($categories)
@foreach($categories as $cat)
<label class="text-gray-700" for="category">
Category:
<select wire:change="choose($event.target.value)" id="animals" class="w-full block w-52 py-2 px-3 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500" name="animals">
<option disabled selected >
Selecione...
</option>
@foreach($cat as $c)
<option value="{{ $c->getId() }}" wire:key="{{ $c->getId() }}">{{ $c->getName() }}</option>
@endforeach
</select>
</label>
@endforeach
@endif
有可能动态地创建新的select
输入吗?