【问题标题】:Compiling data array to pass to Materialize Autocomplete编译数据数组以传递给 Materialise 自动完成
【发布时间】:2019-04-27 23:11:00
【问题描述】:

我正在尝试将自定义数据数组加载到 Materialize 的自动完成功能中。当我使用文档中的测试数据时它可以工作,但是当我使用我自己的数组时它不是。我已经尝试了各种方法,但无法解决这个问题。我敢肯定这是世界上最简单的事情......

感谢您的帮助

我创建了一个JS Fiddle

这是Official Documentation


文档代码(工作)

$(document).ready(function(){
    $('input.autocomplete').autocomplete({
      data: {
        "Apple": null,
        "Microsoft": null,
        "Google": 'https://placehold.it/250x250'
      },
    });
  });


我的代码(不工作!)
entries = [];

// Gather the info from the page
$(".entry_list .entry").each( function() {

    name = $(this).find(".name").text();

    // This is where I think I am going wrong somehow!
    // Have tried {name: name, image: null}, {value: name.., {string: name... etc, nothing is working
    entries.push(name);

});

// This confirms that the array isn't empty
console.log("- Found " + entries.length); 

$('input.autocomplete').autocomplete({
  data: entries,
});

【问题讨论】:

    标签: javascript arrays autocomplete materialize


    【解决方案1】:

    你可以这样试试。

    entries = {};
    
    $(".entry_list .entry").each( function() {
          name = $(this).find(".name").text();
          entries[name] = null;
      });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-20
      • 1970-01-01
      相关资源
      最近更新 更多