StringBuilder builder = new StringBuilder();
for (DataSet dataSet : config.getDatasets()) {
// initialize Bloodhound instances it the source is a Bloodhound object
if (dataSet.getSource() instanceof Bloodhound) {
Bloodhound bh = (Bloodhound) dataSet.getSource();
String bhParams = bh.getConfig().isEmpty() ? "" : bh.getConfig().toJsonString();
builder
.append(String.format("var %s = new Bloodhound(%s);", bh.getName(), bhParams));
builder.append(String.format("%s.initialize();", bh.getName()));
}
}
JQuery functionCall = $(this).chain("typeahead", config, config.getDatasets());
builder.append(functionCall.get());