2

私は 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.

これを解決する方法はありますか?

4

1 に答える 1

4

Ok。多くの検索と掘り下げを行った後、私はそれを解決することができました。「ワイルドカード」オプションがありませんでした。

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

そこで、上記のように「ワイルドカード」オプションを追加すると、うまくいきました。

于 2015-05-05T10:14:31.507 に答える