Yii2: Jui Auto Complete Widget how to?(Yii2:Jui Auto Complete Widget 怎么做?)
本文介绍了Yii2:Jui Auto Complete Widget 怎么做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 yii2 Jui 自动完成小部件.
I am trying to use yii2 Jui autocomplete widget.
我有这段代码可以正确显示自动完成日期,但我无法保存数据.
I have this code which is showing the auto-complete date correctly, but I am not able to save the data.
$data=ArrayHelper::map(State::find()->all(), 'id', 'state_name' );
$data=array_merge($data);
然后
echo 'State' .'<br>';
echo AutoComplete::widget([
'model'=>$model,
'attribute' => 'state_id',
'clientOptions' => [
'source' => $data,
],
]);
任何解决方案将不胜感激.谢谢.
Any solution will be greatly appreciated. Thanks.
推荐答案
好的,我找到了解决方案,它是这样的:
Ok I found the solution, it goes like this:
use yiijuiAutoComplete;
use yiiwebJsExpression;
那么:
$data = State::find()
->select(['state_name as value', 'state_name as label','id as id'])
->asArray()
->all();
然后
echo 'State' .'<br>';
echo AutoComplete::widget([
'name' => 'State',
'id' => 'ddd',
'clientOptions' => [
'source' => $data,
'autoFill'=>true,
'select' => new JsExpression("function( event, ui ) {
$('#city-state_name').val(ui.item.id);//#City-state_name is the id of hiddenInput.
}")],
]);
最后:
<?= Html::activeHiddenInput($model, 'state_name')?>
仅此而已.希望有人会发现它有用.谢谢.
That is all. Hope some one will find it useful. Thanks.
这篇关于Yii2:Jui Auto Complete Widget 怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:Yii2:Jui Auto Complete Widget 怎么做?


猜你喜欢
- 没有作曲家的 PSR4 自动加载 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Laravel 仓库 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01