Laravel Livewire组件&x2019;s属性没有’;我们没有按预期更新

Laravel Livewire组件&x2019;s属性没有’;我们没有按预期更新,laravel,laravel-livewire,Laravel,Laravel Livewire,问题在于表单的上下文,该表单用于编辑角色的属性,包括通过复选框选择的关联权限 加载表单后,某些权限的复选框会根据检索到的角色数据按预期选中。可以选择和取消选择空复选框,更改将反映在浏览器的请求有效负载预览数组中,尽管添加的新值在数组中显示为字符串,如您所见: role_permissions: [1, 2, 3, 4, 5, "6"] 然而,这就是问题所在,当取消选择加载表单时默认选中的复选框时,它们的行为异常,不允许取消选择多个复选框,并且浏览器上的数组的请求负载预览根本

问题在于表单的上下文,该表单用于编辑角色的属性,包括通过复选框选择的关联权限

加载表单后,某些权限的复选框会根据检索到的角色数据按预期选中。可以选择和取消选择空复选框,更改将反映在浏览器的请求有效负载预览数组中,尽管添加的新值在数组中显示为字符串,如您所见:

role_permissions: [1, 2, 3, 4, 5, "6"]
然而,这就是问题所在,当取消选择加载表单时默认选中的复选框时,它们的行为异常,不允许取消选择多个复选框,并且浏览器上的数组的请求负载预览根本不会得到更新

拉维视图:

<div class="card-body">
    <livewire:roles.form-edit :role="$role" />
</div>
Livewire视图:

<form wire:submit.prevent="update" accept-charset="UTF-8" id="edit_role_form" class="form-horizontal">

    <x-input.text label="Name" attribute="name" />

    <x-input.checkboxes label="Permissions" attribute="role_permissions" :options="$permissions" :entity-options="$role_permissions" />

    <x-input.textarea label="Notes" attribute="notes" />

    <x-input.submit label="Save" />

</form>

Laravel组件视图:

@props([
    'label',
    'attribute',
    'options',
    'entityOptions'
])

<div class="form-group row">
    <label for="{{ $attribute }}" class="col-md-3 control-label">{{ __($label) }}</label>
    <div class="col-md-9">
        <ul class="list-unstyled row checkboxes-list">
            <?php $counter = 0 ?>
            @foreach($options as $option)
                @if($counter == 0)
                    <div class="col-lg-4 checkboxes-list-bottom-divider">
                @elseif($counter != 0 && $counter % 5 == 0)
                    </div>
                    <div class="col-lg-4 checkboxes-list-bottom-divider">
                @endif
                <li>
                    <label>
                        <input wire:model="{{ $attribute }}" {{ $attributes }} type="checkbox" value="{{ $option->id }}" placeholder="" {{ (in_array($option->id, $entityOptions)) ? 'checked' : '' }}> {{ $option->label }}
                    </label>
                </li>
                <?php $counter++ ?>
            @endforeach
            </div>
        </ul>
    </div>
</div>
@props([
“标签”,
'属性',
“选项”,
“实体选项”
])
{{{($label)}
    @foreach($options作为$option) @如果($counter==0) @elseif($counter!=0&&$counter%5==0) @恩迪夫
  • id,$entityOptions))?'选中“:”}>{{$option->label}
  • @endforeach
Laravel版本:^7.0

Livewire版本:^1.3

更新:我刚刚摆脱了Laravel组件视图,并重构了Livewire视图中的所有相关代码,但它也不起作用。同样的行为。我被Livewire困在这一点上了


解决了。我仍然爱着Livewire。我真的不想学习Javascript框架。

它是如何解决的?它是如何解决的?
@props([
    'label',
    'attribute',
    'options',
    'entityOptions'
])

<div class="form-group row">
    <label for="{{ $attribute }}" class="col-md-3 control-label">{{ __($label) }}</label>
    <div class="col-md-9">
        <ul class="list-unstyled row checkboxes-list">
            <?php $counter = 0 ?>
            @foreach($options as $option)
                @if($counter == 0)
                    <div class="col-lg-4 checkboxes-list-bottom-divider">
                @elseif($counter != 0 && $counter % 5 == 0)
                    </div>
                    <div class="col-lg-4 checkboxes-list-bottom-divider">
                @endif
                <li>
                    <label>
                        <input wire:model="{{ $attribute }}" {{ $attributes }} type="checkbox" value="{{ $option->id }}" placeholder="" {{ (in_array($option->id, $entityOptions)) ? 'checked' : '' }}> {{ $option->label }}
                    </label>
                </li>
                <?php $counter++ ?>
            @endforeach
            </div>
        </ul>
    </div>
</div>