[英]Uncaught TypeError: this.dropdownEl is null when initializing Materialize autocomplete
I use Materialize v1 and its autocomplete.我使用 Materialize v1 及其自动完成功能。 I used it before.
我以前用过。 I reused the code but I am getting
Uncaught TypeError: this.dropdownEl is null
, I did not find anything useful on the net regarding this error.我重用了代码,但我得到了
Uncaught TypeError: this.dropdownEl is null
,我在网上没有找到任何关于这个错误的有用信息。 I tried to simplify the initialization and debug but nothing work.我试图简化初始化和调试,但没有任何效果。
hm, Chrome throws this error Uncaught TypeError: Cannot set property 'tabIndex' of null
嗯,Chrome 抛出此错误
Uncaught TypeError: Cannot set property 'tabIndex' of null
Uncaught TypeError: this.dropdownEl is null
value https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js:6
n https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js:6
value https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js:6
value https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js:6
value https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js:6
s https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js:6
value https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js:6
value https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js:6
setAutocomplete https://n-mh3s4ggu24p7gzei6l4cpyqn5d5354dk4egvm7y-0lu-script.googleusercontent.com/userCodeAppPanel:159
cf https://n-mh3s4ggu24p7gzei6l4cpyqn5d5354dk4egvm7y-0lu-script.googleusercontent.com/static/macros/client/js/3342396747-mae_html_user_bin_i18n_mae_html_user__cs.js:73
I call Google application script that returns autocomplete data我调用返回自动完成数据的 Google 应用程序脚本
document.addEventListener("DOMContentLoaded", function(){
google.script.run.withSuccessHandler(setAutocomplete)
.getAutocompleteData();
});
and then I set the autocomplete然后我设置自动完成
function setAutocomplete(vraceno){
console.log(vraceno);
var elems = document.querySelectorAll('.autocomplete');
console.log(elems.length)
console.log(elems[0].id)
var data = {
"Apple": null,
"Microsoft": null,
"Google": "https://placehold.it/250x250"
}
var options = {
//data : vraceno.autocomplete,
data : data,
limit : 2,
// onAutocomplete : function(txt) {
// onAutocomplete(txt);
// },
};
console.log("before");
var instanceAutocomplete = M.Autocomplete.init(elems, options);
console.log("after");
console.log(instanceAutocomplete)
//autocomplete = vraceno;
}
and from the console screenshot并从控制台截图
we can see that
我们可以看到
var instanceAutocomplete = M.Autocomplete.init(elems, options);
var instanceAutocomplete = M.Autocomplete.init(elems, options);
is the issueThe HTML used is使用的 HTML 是
<div class="col s12 m6 l3">
<label for="autocomplete">vyhledávání podle jména, příjmení, id</label>
<input placeholder="" id="auto" name="autocomplete" type="text" class="autocomplete" autocomplete="off" />
</div>
Someone could help me to make the Materialize autocomplete to work?有人可以帮助我使 Materialize 自动完成功能正常工作吗?
The problem happened because the input field was not wrapped inside a div with the class input-field:问题的发生是因为输入字段未包含在带有 class 输入字段的 div 中:
<div class="col s12 m6 l3">
<label for="autocomplete">vyhledávání podle jména, příjmení, id</label>
<input placeholder="" id="auto" name="autocomplete" type="text" class="autocomplete" autocomplete="off" />
</div>
Adding a div with the class "input-field" solved this problem.添加一个带有 class “输入字段”的 div 解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.