jquery - 无法设置未定义的属性“url”
问题描述
在下面的示例中,我创建了typeahead
该类的一个实例
var ta = $.typeahead({
input: '.super',
minLength: 0,
maxItem: 15,
order: "asc",
hint: true,
href: "",
searchOnFocus: true,
display: ["name"],
template: "{{name}}",
source: {
"SearchResults": {
//ajax: {
// url: "/search/" + id,
// path: ""
//}
}
},
callback: {
onClickAfter: function (node, a, item, event) {
event.preventDefault;
debugger;
}
},
debug: true
});
稍后,通过使用id
通过以下方法获得的变量
$("input").focus(function () {
id = $(this).attr("id");
ta.source.ajax.url = "/search/" + id;
});
我得到了,Cannot set property 'url' of undefined
因为ta.source.ajax
实际上是空的。我该如何解决?
简而言之,我不想为表单的每个输入创建重复的代码
解决方案
推荐阅读
- python - Selenium 未在发现网站登录时单击“登录”按钮
- python - pip install pymsgbox offline 总是失败
- c++ - 如何阅读 C++ 位域定义的语法?
- java - Android 最可靠的数据压缩算法是什么?
- sql-server - 如何在 SQL Server 中编写触发器主体
- java - 您可以混合使用抽象数据类型吗?例如地图的优先队列?
- php - 另一个 PHP 中的 PHP
- laravel-dusk - Laravel 8 Dusk:使用 Jetstream 和 Inertia JS 测试登录不起作用
- php - Apache2 RewriteRule 在图像 docker.io/library/php:7.4-apache 的容器中不起作用
- kubernetes - Prometheus Operator:无法访问 Prometheus 实例