skeeks / yii2-widget-dual-listbox
为 Yii 2 的双列表框小部件
Requires
This package is auto-updated.
Last update: 2024-08-29 04:31:31 UTC
README
为 Yii 框架 2.0 提供的双列表框。
描述
skeeks\widget\duallistbox\WidgetDualListbox 小部件是 Bootstrap Dual Listbox 的 Yii 2 封装。
要求
- Yii 版本 2.0.0 或更高
使用方法
-
将
skeeks/yii2-widget-dual-listbox
添加到您的项目composer.json
文件中,并让 Composer 配置您的项目。"require": { "php": ">=5.4.0", "yiisoft/yii2": "*", "yiisoft/yii2-bootstrap": "*", "yiisoft/yii2-swiftmailer": "*", "skeeks/yii2-widget-dual-listbox": "dev-master" },
-
在您的视图中使用
skeeks\widget\duallistbox\WidgetDualListbox::widget()
代替yii\helpers\Html::listBox()
、yii\helpers\Html::activeListBox()
或yii\widgets\ActiveField::listBox()
。-
使用 name 和 selection 替换 Html::listBox()
use skeeks\widget\duallistbox\WidgetDualListbox; ... <?php $options = [ 'multiple' => true, 'size' => 20, ]; // echo Html::listBox($name, $selection, $items, $options); echo DualListbox::widget([ 'name' => $name, 'selection' => $selection, 'items' => $items, 'options' => $options, 'clientOptions' => [ 'moveOnSelect' => false, 'selectedListLabel' => 'Selected Items', 'nonSelectedListLabel' => 'Available Items', ], ]); ?>
-
使用 model 和 attribute 替换 Html::activeListBox()
use skeeks\widget\duallistbox\WidgetDualListbox; ... <?php $options = [ 'multiple' => true, 'size' => 20, ]; // echo Html::activeListBox($model, $attribute, $items, $options); echo WidgetDualListbox::widget([ 'model' => $model, 'attribute' => $attribute, 'items' => $items, 'options' => $options, 'clientOptions' => [ 'moveOnSelect' => false, 'selectedListLabel' => 'Selected Items', 'nonSelectedListLabel' => 'Available Items', ], ]); ?>
-
使用 model 和 attribute 替换 ActiveField::listBox()
use skeeks\widget\duallistbox\WidgetDualListbox; ... <?php $options = [ 'multiple' => true, 'size' => 20, ]; // echo $form->field($model, $attribute)->listBox($items, $options); echo $form->field($model, $attribute)->widget(WidgetDualListbox::className(),[ 'items' => $items, 'options' => $options, 'clientOptions' => [ 'moveOnSelect' => false, 'selectedListLabel' => 'Selected Items', 'nonSelectedListLabel' => 'Available Items', ], ]); ?>
-
-
在服务器端收集用户输入,就像使用具有多选的单个列表框一样。请注意,输入值将是一个数组。
如果您在处理用户输入时遇到困难,请阅读 示例代码,该代码演示了如何使用双列表框处理数组格式中的数据。
skeeks\widget\duallistbox\WidgetDualListbox 的属性
-
name @var string
输入名称。
-
selection @var array
选定的值。
-
model @var yii\base\Model
模型对象。
-
attribute @var string
属性名称。
-
items @var array
选项数据项。数组键是选项值,数组值是对应的选项标签。
-
options @var array
列表框的名称-值对标签选项。
-
clientOptions @var array
Bootstrap Dual Listbox 的名称-值对选项。有关详细信息,请参阅 初始化参数对象 部分,该部分位于 Bootstrap Dual Listbox 的官方文档中。
前 6 个属性对应于 Html::listBox()
、Html::activeListBox()
和 ActiveField::listBox()
中使用的参数。
请注意,您必须使用 name-selection 对或 model-attribute 对。前者用于替换 Html::listBox()
,后者用于 Html::activeListBox()
和 ActiveField::listBox()
。
SkeekS CMS (Yii2) — 快速、简单、高效!
skeeks.com | cms.skeeks.com