我在一个livewire组件中有一个select2。一切正常,但在我的编辑视图中,选中的选项不会在框中显示为选中。当我打开下拉列表时,它们显示为突出显示,因此数据来自后端。
<div wire:ignore class="col-8">
<select wire:model="notificationType" class="form-control select2 text-sm"
multiple="multiple">
@foreach($notificationTypeOptions as $key => $option)
<option value="{{ $key }}">{{ $option }}</option>
@endforeach
</select>
</div>
$('.select2').select2({
width: '100%',
tags: true,
multiple: "multiple",
});
$('.select2').on('change', function (e) {
var data = $('.select2').val();
@this.set('notificationType', data);
});如果有人能帮上忙的话。
发布于 2021-03-06 00:53:43
对您的选择框使用单独的id,并按id调用select2
$('#edit-select').select2()
$('#create-select').select2()发布于 2021-07-01 21:22:00
在刀片组件中使用以下代码:
@if (in_array($key, $notificationType)) {{'selected'}} @endif所有内容都只是在select选项标签中进行了更改:如下代码:
<option value="{{$key}}" @if (in_array($key, $notificationType)) {{'selected'}} @endif>{{ $option }}</option>https://stackoverflow.com/questions/66494431
复制相似问题