Я пытаюсь использовать typeahead
с результатами Parse.com. Я думал, что Parse
возвращает JSON
объектов, но кажется, что следующий метод не распознает его. Кто-нибудь может понять, что случилось? Или, может быть, есть более простой способ заставить его работать (в конце я хочу иметь возможность искать через два поля каждого объекта).Bootstrap Typeahead с Parse.com
Насколько я получаю это (благодаря этому: https://github.com/bassjobsen/Bootstrap-3-Typeahead):
function queryListy(){
Parse.Cloud.run('queryList', {}, {
success: function(result) {
var $input = $('#query');
$input.typeahead({source:result,
autoSelect: true});
$input.change(function() {
var current = $input.typeahead("getActive");
if (current) {
// Some item from your model is active!
if (current.name == $input.val()) {
// This means the exact match is found. Use toLowerCase() if you want case insensitive match.
} else {
// This means it is only a partial match, you can either add a new item
// or take the active if you don't want new items
}
} else {
// Nothing is active so it is a new value (or maybe empty value)
}
});
},
error: function(error) {
console.log(error);
}
});
}
Когда я поставил [{id: "someId1", name: "Display name 1"}, {id: "someId2", name: "Display name 2"}]
вместо result
это работает так основной механизм кажется правильным.
О, человек, это отличное разрешение! Благодаря! –