laravel - 编辑表单中的 Select2 不会触发编辑表单中的选定值 - Livewires
问题描述
我在 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);
});
请如果有人可以帮助...
解决方案
在刀片组件中使用此代码:
@if (in_array($key, $notificationType)) {{'selected'}} @endif
一切按原样仅在选择选项标签中发生变化:如下面的代码:
<option value="{{$key}}" @if (in_array($key, $notificationType)) {{'selected'}} @endif>{{ $option }}</option>
推荐阅读
- amazon-web-services - 所有节点上的 Kubernetes DaemonSet Pods 调度都需要一个
- c - 在这个问题中,哪一个被称为函数声明(原型)?
- android - Gradle 错误:服务器返回 HTTP 响应代码:403 用于 URL:http://services.gradle.org/distributions/gradle-2.2.1-all.zip
- javascript - (React Context Beginner) React Context doesn't stat when changing page using react-rooter-dom
- python - 为什么这个语法对 python 不正确?
- npm - NPM:使用 npm-automation-token 获取 403 whoami
- list - 在 Haskell 中合并 3 个列表
- http - Tomcat 9 总是给出地址已经用于 http/https 连接器
- spring-cloud - 如何在kafka消费者中使用spring cloud sleuth traceId
- sharepoint - 如何获取不同共享点站点的 ACL