javascript - 为什么我无法加载用于 myAccount.ejs 的 autocomplete.js 模块?
问题描述
所以基本上我正在尝试设置自动完成,我正在关注他们的入门示例:
我的帐户.ejs
<input type="text" id="countries">
<script src="/javascripts/autocomplete.js" ></script>
自动完成.js
//Whenever I require anything the script fails, I've checked by watching alert('hello') come in and out
const autocomplete = require('autocompleter');
var countries = [
{ label: 'United Kingdom', value: 'UK' },
{ label: 'United States', value: 'US' }
];
var input = document.getElementById("country");
autocomplete({
input: input,
fetch: function(text, update) {
text = text.toLowerCase();
// you can also use AJAX requests instead of preloaded data
var suggestions = countries.filter(n => n.label.toLowerCase().startsWith(text))
update(suggestions);
},
onSelect: function(item) {
input.value = item.label;
}
});
alert('hello');
这真的很奇怪,因为在我的控制器文件夹中,我可以要求模块没有问题,所以我不知道/看到我缺少什么,是的,它就在我的头上飞过,是的,我很愚蠢。如果我什至无法加载它,我什至不知道如何使用这个 npm 模块自动完成......
解决方案
推荐阅读
- node.js - Nginx 子文件夹中的 Node.js 应用程序与 WSS 连接到同一服务器
- http - 路由器返回 404 编码斜线 (%2F)
- anylogic - Java 应用程序调用 Anylogic(无导出)
- javascript - 如何修复我的进度条出现故障?
- python - Pygame以与玩家相同的方式移动绘制的矩形(不是图像),包括旋转
- python - Python - 如何使用字典正确绘制折线图?
- python - 你如何在 Pandas 中创建组合滚动组
- c++ - 将当前模板用作模板参数之一的模板参数
- python-3.x - 使用 wtforms 进行烧瓶网格编辑
- class - R:读取数据表时指定列类的目的