承接 etdte/livewire-multiselect 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

etdte/livewire-multiselect

最新稳定版本:2.2

Composer 安装命令:

composer require etdte/livewire-multiselect

包简介

Livewire multiselect

README 文档

README

Requirements

Installation

You can install the package via composer:

composer require etdte/livewire-multiselect

Usage

1) Add LivewireMultiselect\HasSelect trait to your component

class Index extends Component
{
    use LivewireMultiselect\HasSelect;

2) Add variables for an available options and a selected ones to your component

// for selected options - multiple
public ?array $teamFilter = null;
// for selected option - single
public int|string|null $teamFilter = null;

// available options
public ?Collection $teams = null;

3) Add the select to your page

<livewire:multiselect parentId="{{ $this->getId() }}"
                      name="teamFilter"
                      label="name"
                      :selected="$teamFilter"
                      title="{{ __('Teams') }}"
                      :options="$teams"
                      :multiselect="true"
                      styles="w-full"></livewire:multiselect>

4) Add select listener to your component (only for Livewire v2)

If you're using Livewire v2, you need to manually add the event listener in your component:

protected $listeners = ['select'];

For Livewire v3, this is no longer needed.

Events

Multiselect component emits a multiselect.select event, which is caught by HasSelect trait and sets values to a proper variables in your component.
This trait also calls selected function on your component, if it exists, and passes a select name and selected items. You can define a selected method in your component to react on the changes:
Works only if :simpleForm="false"

multiselect

public function selected(string $name, array $value)
{
    if ($name === 'teamFilter') {
        // do something
    }
}

select

public function selected(string $name, int|string|null $value)

Props

Property Arguments Default Example
trackBy <String> - Used to compare objects. id trackBy="id"
label <String> - Object property in option, that will be visible in the dropdown. name label="name"
name <String> - Used to name inputs & identify multiple selects on a page.
Must be the same as a variable name in your component which accepts selected items
required name="teamFilter"
options <Illuminate\Support\Collection> - Available options. required :options="$teams"
selected <Array,Integer,String> - Used to define selected options on a page loading.
Variable name should be the same as a name prop value.
null :selected="$teamFilter"
title <String> - Label title for the select on a page. null title="Teams"
multiselect <Boolean> - Determines if the select is multiple. false :multiselect="true"
showEmptyOption <Boolean> - Determines if an empty option displays on the select.
Works only for single selects (:multiselect="false")
true :showEmptyOption="false"
simpleForm <Boolean> - Determines if a html input should be added to a page.
Useful when a select is placed outside a livewire component, like a html form which makes a regular http request.
false :simpleForm="true"
parentId <String> - Determines which component a select belongs to.
Highly recommended to define it when you have more then one level component depth, with the same selects name on each level.
null parentId="{{ $this->getId() }}"
styles <String> - Classes of the root select wrapper. col-span-1 styles="w-full"

Additional functionality

You can refresh selected items by calling in your component

// reset component variables
$this->reset('teamFilter');
$this->anotherFilter = [2,3];
// reset options on all component selects
$this->dispatch('refresh', $this)->to('multiselect'); // Livewire 3
$this->emitTo('multiselect', 'refresh', $this); // Livewire 2

// you can also do something like this,
// BUT ALL NOT PASSED SELECTS, WITHIN THE COMPONENT, WILL BE RESET TO EMPTY.
$this->dispatch('refresh', ['id' => $this->getId(), 'teamFilter' => [2]])->to('multiselect'); // Livewire 3
$this->emitTo('multiselect', 'refresh', ['id' => $this->id, 'teamFilter' => [2]]); // Livewire 2

You can also refresh available options

$teams = $this->teams->take(3);
// $teams - available options
// 'teamFilter' - select name
// $this->getId() - component id(parentId)
$this->dispatch('refreshOptions', $teams, 'teamFilter', $this->getId())->to('multiselect'); // Livewire 3
$this->emitTo('multiselect', 'refreshOptions', $teams, 'teamFilter', $this->id); // Livewire 2

Customizing

You can customize a select look by publishing its view

php artisan vendor:publish --tag=multiselect:views

License

The MIT License (MIT). Please see License File for more information.

etdte/livewire-multiselect 适用场景与选型建议

etdte/livewire-multiselect 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.64k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 01 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 etdte/livewire-multiselect 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 etdte/livewire-multiselect 我们能提供哪些服务?
定制开发 / 二次开发

基于 etdte/livewire-multiselect 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.64k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2024-01-19