我是Twitter Typeahead(typeahead.js 0.11.1)的新手,我正在尝试使用remote选项使用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.


有什么想法可以解决这个问题吗?

最佳答案

好。经过大量搜索和挖掘之后,我设法解决了这个问题。缺少“通配符”选项。

var firstNames = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.whitespace,
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    remote: {
        url: '/hub/get_user_firstname_suggestions.json?searchTerm=%QUERY',
        wildcard: '%QUERY'
    }
});


因此,如上所示,我添加了“通配符”选项,并且达到了目的。

关于javascript - Twitter Typeahead猎狗远程Spring MVC字符解码失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30039734/

10-13 09:12