【发布时间】:2020-06-10 12:57:49
【问题描述】:
正如您在打印屏幕上看到的那样,下拉菜单被渲染了。谁能告诉我如何渲染它?
代码:
final Select2Choice<Country> originCountryDD = new Select2Choice<>("originCountry", new PropertyModel<Country>(this, "originCountry"), new CountryProvider());
private class CountryProvider extends ChoiceProvider<Country> {
@Override
public void query(String codeWithNameFragment, int i, Response<Country> response) {
if(codeWithNameFragment == null || "".equals(codeWithNameFragment)) {
response.addAll(countryDao.findAllWithStations());
} else {
response.addAll(countryDao.findByFragment(codeWithNameFragment));
}
}
@Override
public void toJson(Country country, JSONWriter jsonWriter) throws JSONException {
jsonWriter.key("id").value(country.getId()).key("text").value(country.getNameWithCode());
}
@Override
public Collection<Country> toChoices(Collection<String> collection) {
Collection<Country> countries = new ArrayList<>();
List<Country> countryList = countryDao.findAll();
for(String id : collection){
for(Country country : countryList) {
if(country.getId().equals(Long.valueOf(id))) {
countries.add(country);
}
}
}
return countries;
}
}
这是我的代码。我不知道,如何使 select2 呈现下降趋势。任何帮助打招呼。
【问题讨论】:
-
嗨,我不知道是否有针对此的特定服务器配置,但您可能会在另一个问题中找到解决方案:stackoverflow.com/questions/19983601/…
标签: jquery-select2 wicket