我正在尝试将自定义数据数组加载到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,
});
答案 0 :(得分:1)
您可以尝试这样。
entries = {};
$(".entry_list .entry").each( function() {
name = $(this).find(".name").text();
entries[name] = null;
});