maxdancepro / yii2-autocomplete
带有 Id 字段小部件的 Yii2 Jui 自动完成
1
2019-02-09 23:55 UTC
Requires
- yiisoft/yii2: *
- yiisoft/yii2-jui: ~2.0.0
Requires (Dev)
- phpunit/phpunit: 4.*
This package is auto-updated.
Last update: 2024-09-10 12:09:12 UTC
README
带有 Id 字段小部件的 Yii2 Jui 自动完成
安装
推荐通过 composer 安装此扩展。
或者
php composer.phar require --prefer-dist maxdancepro/yii2-autocomplete "*"
或者在你的 composer.json
文件的相应部分添加以下内容:
"maxdancepro/yii2-autocomplete": "*"
在 composer.json
文件中添加以下内容到所需部分:
使用
扩展安装完成后,只需在代码中使用它即可
<?= $form->field($model, 'attribute_id')->widget(AutoComplete::className()); ?>
用于 Ajax 请求
echo $form->field($model, 'attribute')->widget(AutoComplete::className(), [ 'clientOptions' => [ 'source' => Url::to(['/controller/autocomplete']) ] ])
默认情况下,使用 Ajax 请求 (Url::to(['/attibute/autocomplete']))
echo $form->field($model, 'attribute_id')->widget(AutoComplete::className());
或者使用数组
echo $form->field($model, 'attribute_id')->widget(AutoComplete::className(), [ 'clientOptions' => [ 'source' => [ ['id' => 1, 'label' => 'Label 1'], ['id' => 2, 'label' => 'Label 2'], ... ] ] ])