简体   繁体   English

我怎样才能在 laravel livewire 中检查多少个复选框

[英]how can i get how many checkboxes are checked in laravel livewire

This table and i need once the user selects checkbox,the number of selected (0 in pic) updated and save this value这个表和我需要一旦用户选择复选框,选择的数量(图片中的 0)更新并保存这个值

table contain select all checkbox and the second for the single checkbox and some text表包含 select 所有复选框和第二个用于单个复选框和一些文本桌子

the code for the first checkbox for select all checkbox and the second for the single checkbox select 所有复选框的第一个复选框的代码和单个复选框的第二个复选框全选复选框的第一个复选框和单个复选框的第二个复选框的代码

In your component you want to have an array to hold the selected checkboxes in:在您的组件中,您希望有一个数组来保存选定的复选框:

public array $selectedItems = [];

Then, in your blade you want to link your checkbox to this array:然后,在您的刀片中,您希望将复选框链接到此数组:

<input type="checkbox" value="{{ $item->id }}" wire:model="selectedItems">

Now you can count($selectedItems) in your blade, or count($this->selectedItems) in your component to know how many are selected.现在您可以在刀片中使用count($selectedItems)或在组件中使用count($this->selectedItems)来了解选择了多少。

Try something like this尝试这样的事情

<input
id="my-id"
wire:model="yourCheckboxModel"
type="checkbox"
@if($yourLivewireVariable)
checked
@endif>

You can use a blade if endif statement to toggle the checked variable, and then use wire model to bound the variable您可以使用刀片 if endif 语句来切换选中的变量,然后使用线 model 绑定变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM