我正在尝试将自定义数据数组加载到 Materialize 的自动完成功能中。当我使用文档中的测试数据时它有效,但当我使用我自己的数组时它不是。我已经尝试了各种方法,但无法解决这个问题。我敢肯定这是世界上最简单的事情......
谢谢你的帮助
我创建了一个 JS Fiddle
文档代码(工作)
$(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/