定制 conquer/select2 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

conquer/select2

最新稳定版本:1.5.4-beta

Composer 安装命令:

composer require conquer/select2

包简介

Yii2 Select2 widget

README 文档

README

Description

Select2 gives you a customizable select box with support for searching, tagging, remote data sets, infinite scrolling, and many other highly used options. For more information please visit Select2

Installation

The preferred way to install this extension is through composer.

To install, either run

$ php composer.phar require conquer/select2 "*" 

or add

"conquer/select2": "*" 

to the require section of your composer.json file.

Usage

Basic usage:

// Form edit view use conquer\select2\Select2Widget; use yii\helpers\ArrayHelper; $form->field($model, 'attribute')->widget( Select2Widget::className(), [ 'items'=>ArrayHelper::map(Catalog::find()->all(), 'id', 'name') ] );

Ajax:

use conquer\select2\Select2Action; ... class SiteController extends Controller { public function actions() { return [ 'ajax' => [ 'class' => Select2Action::className(), 'dataCallback' => [$this, 'dataCallback'], ], ]; } /**  *   * @param string $q  * @return array  */ public function dataCallback($q) { $query = new ActiveQuery(Catalog::className()); return [ 'results' => $query->select([ 'catalog_id as id', 'catalog_name as text', ]) ->filterWhere(['like', 'catalog_name', $q]) ->asArray() ->limit(20) ->all(), ]; } } // Form edit view: $form->field($model, 'attribute')->widget( Select2Widget::className(), [ 'ajax' => ['site/ajax'] ] );

Jquery Events:

Array the Select2 JQuery events. You must define events in event-name => event-function format. All events will be stacked in the sequence. Refer the plugin options documentation for details.

For example:

$form->field($model, 'attribute')->widget( Select2Widget::className(), [ 'events' => [ 'select2:open' => "function() { log('open'); }", ] ] );

Initialization of multiple selection in case of using ajax and custom templates.

<?= $form->field($model, 'multipleItems')->widget(Select2Widget::className(), [ 'options' => [ 'placeholder' => 'Select items ...', ], 'ajax' => Url::to(['items/search']), 'multiple' => true, 'items' => ArrayHelper::map($model->multipleItems, 'id', 'text'), // Initial data the same, as returned results from Ajax request items/search 'data' => $model->multipleItems, 'settings' => [ 'ajax' => ['delay' => 250], 'minimumInputLength' => 1, 'minimumResultsForSearch' => -1, /**   * Handlebars here is used as example of using template engine  * If you will not provide initial data,  * custom templates will not access additional info of items  */ 'templateResult' => 'js:Handlebars.compile($("#template-result").html())', 'templateSelection' => 'js:Handlebars.compile($("#template-selection").html())', 'escapeMarkup' => 'js:function(markup){ return markup; }', ], ]) ?>

License

conquer/select2 is released under the MIT License. See the bundled LICENSE for details.

统计信息

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

GitHub 信息

  • Stars: 16
  • Watchers: 4
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固