编译数据数组以传递给 Materialise Autocomplete
Compiling data array to pass to Materialize Autocomplete
我正在尝试将自定义数据数组加载到 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;
});
我正在尝试将自定义数据数组加载到 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;
});