简体   繁体   English

如何使用autoComplete.js?

[英]How to use autoComplete.js?

I'm trying to use autoComplete.js . 我正在尝试使用autoComplete.js

I have npm installed it: 我已经安装了npm:

npm i @tarekraafat/autocomplete.js

Then imported it in a js file: 然后将其导入到js文件中:

import autoComplete from "@tarekraafat/autocomplete.js/dist/js/autoComplete";

Also added a div with an id of autoComplete: 还添加了一个id为autoComplete的div:

<input id="autoComplete" tabindex="1">    <!-- Default "id" value = "autoComplete">`

In the file where I imported the library, I copied the code that is on the website in step 4 of the how to use part . 在导入库的文件中,我复制了如何使用part的步骤4中网站上的代码。

But, I get the error: 但是,我得到了错误:

autocompletejs.js:43 Uncaught ReferenceError: resultsListID is not defined autocompletejs.js:43未捕获的ReferenceError:未定义resultsListID

What am I doing wrong? 我究竟做错了什么? I followed the steps as in the documentation but I get this error... 我按照文档中的步骤进行操作,但出现此错误...

Any ideas on what might be the issue? 关于可能是什么问题的任何想法?

This error is caused, by the fact that here 此错误是由以下事实引起的:

resultsList: {                       // Rendered results list object      | (Optional)
        render: true,
        container: source => {
            resultsListID = "food_List";
            return resultsListID;
        },
        destination: document.querySelector("#autoComplete"),
        position: "afterend",
        element: "ul"
    },

resultsListID variable have never been initiated. resultsListID变量从未初始化。 It is possible to fix this byt adding var at the start of where resultsListID is assigned making something like: var resultsListID = "food_List"; 可以通过在分配resultsListID的开头添加var来解决此问题,方法是: var resultsListID = "food_List";

resultsList: {                       // Rendered results list object      | (Optional)
        render: true,
        container: source => {
            var resultsListID = "food_List";
            return resultsListID;
        },
        destination: document.querySelector("#autoComplete"),
        position: "afterend",
        element: "ul"
    },

Noticed, that this part is optional, and if one chooses to keep it, as far as my understanding is going all results will be wrapped in the container, that has id provided in the resultsListID variable 注意,这部分是可选的,如果我选择保留它,就我的理解而言,所有结果都将包装在具有resultsListID变量提供的ID的容器中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM