具有自动完成功能的芯片(没有jQuery和1.0.0-alpha3)不会初始化

时间:2018-01-03 11:26:37

标签: materialize

预期行为

使用Javascript(无jQuery)使用自动完成选项创建Chips组件。

当前行为

运行组件我收到消息

materialize.min.js:6 Uncaught TypeError: Cannot read property '0' of null
at n.value (https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-alpha.3/js/materialize.min.js:6:104488)
    at new n (https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-alpha.3/js/materialize.min.js:6:101364)
    at Function.value (https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-alpha.3/js/materialize.min.js:6:11799)
    at Function.value (https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-alpha.3/js/materialize.min.js:6:106244)

重现步骤

Codepen链接:Using 1.0.0-alpha3

HTML:

<div class="row">
  <div class="col s12 m6">
    Groups:                            
    <div class="chips chips-autocomplete-groups">     </div>
  </div>                       
</div>

JS:

var elem = document.querySelector('.chips-autocomplete-groups');
if (elem != null) {
    var insChipAC = M.Chips.init(elem, {
        placeholder: 'Enter a group',
        secondaryPlaceholder: '+Group',
        autocompleteOptions: {
            data: {
                'Alex': null,
                'Brandy': null,
                'Charlie': null
            },
            limit: Infinity,
            minLength: 1
        }        
    });    
}

1.0.0-alpha2 版本中,我能够创建该组件 Codepen链接:Using 1.0.0-alpha2

环境

  • 使用的版本:1.0.0-alpha3
  • 浏览器名称和版本:Chrome 63.0.3239.108
  • 操作系统和版本(桌面或移动设备):Ubuntu 16.04

1 个答案:

答案 0 :(得分:0)