jquery - 使用 typeahead.js 使用多个数据集时更改输入字段的名称属性
问题描述
我正在使用带有多个数据集的 typeahead.js,如此处所述。我没有使用 Bloodhound,所以我的代码看起来有点不同,如下所示
$('#search .typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'football_team',
source: substringMatcher(football_teams),
templates: {
header: '<h3>Football teams</h3>'
}
},
,{
name: 'basketball_team',
source: substringMatcher(basketball_teams),
templates: {
header: '<h3>Basketball teams</h3>'
}
});
由于它正在使用数据集football_teams
,basketball_teams
我想根据使用的数据集发送不同的 GET 请求。例如,如果我搜索“Arsenal”,选择它并单击 Enter,它应该会发送以下请求?football_team=Arsenal
。
如何name
根据使用的数据集设置输入字段的属性?
我认为它应该很容易实现,但是在谷歌搜索了一段时间后我找不到任何东西......
解决方案
使用cdn-ref try with custom-event
handler for typeahead:select处理选定的选项
用法参考:示例代码(内部项目)
推荐阅读
- python - 在 Pyspark 中过滤嵌套的 JSON 结构并获取字段名称作为值
- javascript - Javascript - 一旦元素具有值的事件
- tcl - 使用 openseesMP 时分析终止?
- javascript - 如何将事件从组件传递到嵌套函数?
- python - “节点”对象没有用于二叉树实现的属性“插入”
- python - 有人想告诉我为什么我的 pygame 代码在使用 pygame Vectors 时会滞后吗?
- android - 如何知道该类在哪个进程中运行?
- c# - 正则表达式替换“整个”十进制数字后不跟某个字符串
- python - EAV数据模型中产品的多个类别的Django ModelForm
- windows-subsystem-for-linux - WSL Ubuntu 18 上带有 SOEM 的 EtherCAT