I am creating a web app using Node js and express. For autocomplete I am using a third party node module called easy-autcomplete . I have followed the documentation and included all the files however I am getting the following error
Uncaught TypeError: $(...).easyAutocomplete is not a function
at HTMLDocument.<anonymous> (post-property.js:289)
at mightThrow (jquery-3.3.1.js:3534)
at process (jquery-3.3.1.js:3602)
post-property.js
$(function(){
let countries = [
{"name": "Afghanistan", "code": "AF"},
{"name": "Albania", "code": "AL"},
{"name": "Algeria", "code": "DZ"},
..
..
]
var options = {
data: countries,
getValue: "name",
list: {
match: {
enabled: true
}
}
};
$("#provider-json").easyAutocomplete(options);
});
post-property.hbs
<div class="row">
..
..
</div>
<script src="/javascripts/post-property.js"></script>
<script src="/scripts/jquery.easy-autocomplete.min.js"></script>
<link rel="stylesheet" href="/scripts/easy-autocomplete.css">
<link rel="stylesheet" href="/scripts/easy-autocomplete.themes.min.css">
app.js
...
app.use('/scripts', express.static(__dirname + '/node_modules/easy-autocomplete/dist/'));
...
I checked for various solutions where I had to move my file from the node modules folder however the error persisted.
You should move the script and css for easy-autocomplete before your own script.
let countries = [ {"name": "Afghanistan", "code": "AF"}, {"name": "Albania", "code": "AL"}, {"name": "Algeria", "code": "DZ"}, ] var options = { data: countries, getValue: "name", list: { match: { enabled: true } } }; $("#basics").easyAutocomplete(options);
<head> <link rel="stylesheet" href="/scripts/easy-autocomplete.css"> <link rel="stylesheet" href="/scripts/easy-autocomplete.themes.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/easy-autocomplete/1.3.5/jquery.easy-autocomplete.min.js"></script> <script src="/javascripts/post-property.js"></script> </head> <body> <div class="row"> <input id="basics" /> </div> </body>
Then don't forget to include jQuery script as mentionned in the documentation
You need to load the plugin / library before your custom code, otherwise it won't exist. jQuery
also needs to be included before both of these scripts
.
Try the following:
<script src="/scripts/jquery.easy-autocomplete.min.js"></script>
<script src="/javascripts/post-property.js"></script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.