javascript - 编译数据数组以传递给 Materialise Autocomplete

标签 javascript arrays autocomplete materialize

我正在尝试将自定义数据数组加载到 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,
});

最佳答案

你可以这样试试。

entries = {};

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

关于javascript - 编译数据数组以传递给 Materialise Autocomplete,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53478873/

相关文章:

Javascript:如何删除数组中字符串中的特定字符值

linux - 在 haskell-vim-now 中更改自动完成的键绑定(bind)

css - Aptana Studio 3.0.7 - CSS 自动完成仅来自 2. 行

shell - 如何从我自己的脚本中为 fish shell 提供制表符补全?

javascript - Angular.js 发送到许多帖子

javascript - 如何在 html 电子邮件内容中显示通过 JS 获取的月份?

javascript - 如何在没有解析的情况下将数据加载到服务中

JavaScript 连接两个对象

C++ 将 int 添加到 int 数组

java - 修复由 2D 数组制成的 BufferedImage 的锯齿状边缘