根据下面的代码,我尝试使用列表填充自动填充文本框。当我console.log()
列表时,我得到了预期的结果,但是当我将列表添加到我的自动完成功能时它没有按预期工作,我只看到列表名称作为建议。截图:
代码:
var childData; // Holds Objects
var exercises = []; // Push exercise names into this
// Obtain Exercises
function exerciseQueries() {
var ref = firebase.database().ref('exercises'); // Reference equal to exercises node
ref.orderByChild('name').on('value', function (snapshot) { // Order by name of exercise
snapshot.forEach(function (childSnapshot) { // Loop, on each hit
// childData will be the actual contents of the child
childData = childSnapshot.val();
console.log(childData);
exercises.push(childData.name);
});
});
}
exerciseQueries(); // Execute function
$(function () {
$('input.autocomplete').autocomplete({
data: {childData: null}
});
console.log(exercises);
});
我试过传递一个对象(childData)和列表(练习);但两个都没有工作。我也尝试过source参数而不是数据,但没有运气。有人可以帮忙吗?
编辑更新的代码(相同的错误)
function exerciseQueries() {
var ref = firebase.database().ref('exercises'); // Reference equal to exercises node
ref.orderByChild('name').on('value', function (snapshot) { // Order by name of exercise
snapshot.forEach(function (childSnapshot) { // Loop, on each hit
// childData will be the actual contents of the child
childData = childSnapshot.val();
console.log(childData);
exercises.push(childData.name);
});
$(function () {
$('input.autocomplete').autocomplete({
data: {childData}
});
});
});
}