如果有人使用带有 GET 的 Bloodhound:
// Typeahead
personsBloodhound = new Bloodhound({
datumTokenizer: function (person) { return person.name; },
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/ajax/Persons/List?nameContains=%QUERY',
ajax: {
beforeSend: function(xhr) {
$(".searching-person").show();
},
data: {
"pageSize": 4,
"otherParam1": "blah",
"otherParam2": "bleh",
}
},
filter: function (response) {
$(".searching-person").hide();
return response.persons;
}
}
});
一个简单地在 URL 中使用 %QUERY。
现在....
如果有人将 Bloodhound 与 POST 一起使用,我应该使用什么来代替 %QUERY?
// Typeahead
personsBloodhound = new Bloodhound({
datumTokenizer: function (person) { return person.name; },
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/ajax/Persons/List',
ajax: {
type: "POST",
beforeSend: function(xhr) {
$(".searching-person").show();
},
data: {
"nameContains": ....WHAT GOES HERE?????......
"pageSize": 4,
"otherParam1": "blah",
"otherParam2": "bleh",
}
},
filter: function (response) {
$(".searching-person").hide();
return response.persons;
}
}
});
如果不清楚,问题是:在 Bloodhound 的遥控器中使用 POST
相当于什么?%QUERY
文档对此并不清楚,(证明): https ://github.com/twitter/typeahead.js/blob/master/doc/bloodhound.md#remote
还尝试使用:
"nameContains": $("#my-input-that-uses-typeahead").val(),
但是没有用。