php - 如何通过 Yii2 kartik typeahead 远程 URL 从文本字段传递动态值
问题描述
我像这样在我的网站中使用 yii2 typeahead
<?=$form->field($model, 'building',['inputOptions' => [
'autocomplete' => 'off']])->widget(Typeahead::className(),[
'name' => 'building_profile',
'options' => ['placeholder' => 'Type your building','class'=>'autocomplete','id'=>'building_profile','autoFocus'=>true],
'pluginOptions' => ['highlight'=>true,'autoselect' => true],
'dataset' => [
[
'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('value')",
'display' => 'value',
'remote' => [
'url' => Url::to(['sale-residential/all-buildings']) . '?q=%QUERY&country_id='.$country_id,
'wildcard' => '%QUERY'
],
'limit'=>10
]
],
'pluginEvents'=>[
"typeahead:select" => "function() { getBuildingDetails(this.value); }",
]
])->label(false);?>
这是我的代码。请看一下。url中有一个country_id。现在我正在向它传递一个静态值。它现在正在工作。但问题是我想将一个动态值从一个文本字段传递到该网址类似于
'url' => Url::to(['sale-residential/all-buildings']) . '?q=%QUERY&country_id='.{get the value from a text field with id my_country}
我该怎么做。提前谢谢。我的文本字段在同一个视图文件中
<?=$form->field($model,'country_id')->textInput(['id'=>'my_country')?>
实际上我的需要是,当我提前输入时,我想通过远程 url 传递用户输入的国家/地区 ID。这就是我想要的
解决方案
推荐阅读
- javascript - 对表格进行排序但表格标题已损坏
- c# - 在 C# 中使用 WordPress REST API 获取帖子作者显示名称
- node.js - Express API 发布请求在本地工作,但在 Heroku 上失败
- python - 如何在 pygame 上显示随机图片(骰子)并为其赋值?
- configuration - 为什么 Serilog LoggerEnrichmentConfiguration 操作未实现
- php - 在对象数组 (JSON) 中编辑对象的特定键值
- sql - 新列取决于条件sql
- sql-server - 我可以从 MSSQL\Backup 文件夹中手动删除 .log 和 .bak 文件吗?
- angular - 从@angular/http 迁移到@angular/common/http 但无法弄清楚
- javascript - 我可以让我的机器人在离线时在特定的文本通道中发送消息吗?