我是Twitter Typeahead的新手(typeahead.js 0.11.1),我正在尝试使用远程选项使用Thymeleaf + Spring MVC进行配置。
这是我的控制器类:
@Controller
public class AutocompleteController {
@Autowired
private IRefDataService refDataService;
@RequestMapping(value = "/get_user_firstname_suggestions.json", method = RequestMethod.GET)
public @ResponseBody List<String> getUserFirstNameSuggestions(@RequestParam("searchTerm") String searchTerm) {
return refDataService.getUserFirstNameSuggestions(searchTerm);
}
}
这是我的javascript代码:
// constructs the suggestion engine
var firstNames = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote:{
url: "/hub/get_user_firstname_suggestions.json?searchTerm=%QUERY"
}
});
//Initialize the Bloodhound suggestion engine
firstNames.initialize();
$([[${'#' + heading.fieldName}]]).typeahead({
hint: true,
highlight: true,
minLength: 2
},
{
name: 'firstNames',
display: 'value',
source: firstNames.ttAdapter()
});
当我尝试运行我的应用程序时,我收到以下消息:
INFO: Character decoding failed. Parameter [searchTerm] with value [%QUERY] has been ignored. Note that the name and value quoted here may be corrupted due to the failed decoding. Use debug level logging to see the original, non-corrupted values.
Note: further occurrences of Parameter errors will be logged at DEBUG level.
我有什么想法可以解决这个问题吗?
答案 0 :(得分:3)
确定。经过大量的搜索和挖掘后,我设法解决了它。缺少“通配符”选项。
var firstNames = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/hub/get_user_firstname_suggestions.json?searchTerm=%QUERY',
wildcard: '%QUERY'
}
});
所以我添加了'wildcard'选项,如上所示,这就是诀窍。