2
我正在嘗試將typeahead
與Parse.com結果一起使用。我認爲Parse
返回JSON
對象,但似乎下面的方法不承認它。任何人都可以發現什麼是錯的?或者也許有更簡單的方法使其工作(最後我希望能夠搜索每個對象的兩個字段)。Bootstrap Typeahead with 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
其工作原理非常基本的機制似乎是正確的。
噢,這是偉大的決議!謝謝! –