【发布时间】:2016-03-21 11:20:28
【问题描述】:
我正在尝试将 typeahead 与 Parse.com 结果一起使用。我认为Parse 返回JSON 对象,但似乎以下方法无法识别它。任何人都可以发现有什么问题吗?或者也许有更简单的方法让它工作(最后我希望能够搜索每个对象的两个字段)。
目前为止(感谢: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 时,它可以正常工作,所以基本机制似乎是正确的。
【问题讨论】:
标签: javascript json twitter-bootstrap parse-platform bootstrap-typeahead