简体   繁体   English

Uncaught TypeError: this.dropdownEl is null 初始化物化自动完成时

[英]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我们可以看到

  • the data was received (it does not matter as I crated test data variable to test the data received)接收到数据(没关系,因为我创建了测试数据变量来测试接收到的数据)
  • there is one "autocomplete" element found找到一个“自动完成”元素
  • the var instanceAutocomplete = M.Autocomplete.init(elems, options); var instanceAutocomplete = M.Autocomplete.init(elems, options); is the issue是问题

The 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.

相关问题 实现:未捕获的TypeError:$(…).scrollSpy不是函数 - Materialize: Uncaught TypeError: $(…).scrollSpy is not a function 未捕获的TypeError:$(…).autocomplete不是函数 - Uncaught TypeError: $(…).autocomplete is not a function materialize-css Uncaught TypeError:Vel不是函数 - materialize-css Uncaught TypeError: Vel is not a function jQuery Uncaught TypeError:$(…).autocomplete不是函数 - jQuery Uncaught TypeError: $(…).autocomplete is not a function 未捕获的类型错误:downloadButton 为 null - Uncaught TypeError: downloadButton is null 未捕获的类型错误:待办事项是 null - Uncaught TypeError: Todos is null 未捕获的类型错误:与 html 一起使用时无法读取 null 的属性“querySelector” - Uncaught TypeError: Cannot read property 'querySelector' of null when using with html 未捕获的TypeError:取消选中复选框时无法读取null的属性&#39;innerHTML&#39; - Uncaught TypeError: Cannot read property 'innerHTML' of null when unchecking checkbox 未被捕获的TypeError:在浏览器上运行时无法将属性&#39;value&#39;设置为null - Uncaught TypeError: Cannot set property 'value' of null when run on browser 未捕获的类型错误:执行定时器 function 时,second_input 为 null - Uncaught TypeError: second_input is null when executing a timer function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM