Select2 下拉列表不显示 Response 响应中的所有项目

Selec2 dropdown isnt show all items in Response response

我对 select 2 有疑问。它不显示所有项目,只显示子集。我在 Select2Choice 上看不到任何显示所有项目的方法。谁能告诉我如何显示整个项目。

代码如下:

originStationDropDown = new Select2Choice<>("originDgfStation", new PropertyModel<Station>(this, "originStation") , new StationsProvider(originCountryDD, productDD));
        ComponentHelper.addLabelAndComponent(originStationDropDown, this, "originStation.label", ComponentOptions.REQUIRED);

 private class StationsProvider extends ChoiceProvider<Station> {

        private Select2Choice<Country> countryDD;
        private DropDownChoice<Product> productDD;

        public StationsProvider(Select2Choice<Country> countryDD, DropDownChoice<Product> productDD) {
            this.countryDD = countryDD;
            this.productDD = productDD;
        }

        @Override
        public void query(String codeNameFragment, int i, Response<Station> response) {
            if(codeNameFragment == null || "".equals(codeNameFragment)) {
                List<Station> stations = stationDao.findByCountryAndProduct(countryDD.getModel().getObject(), productDD.getModel().getObject(), "code");
                for(Station station : stations) {
                    response.add(station);
                }
            } else {
                response.addAll(stationDao.findByCountryAndProductAndFragment(countryDD.getModel().getObject(), productDD.getModel().getObject(), codeNameFragment));
            }
            System.out.println(response.size());
        }

        @Override
        public void toJson(Station station, JSONWriter jsonWriter) throws JSONException {
            jsonWriter.key("id").value(station.getId()).key("text").value(station.getNameWithCode());
        }

        @Override
        public Collection<Station> toChoices(Collection<String> collection) {
            List<Station> stations = new ArrayList<>();
            List<Station> stationList = stationDao.findAll();

            for(String id : collection) {
                for(Station station : stationList) {
                    if(station.getId().equals(Long.valueOf(id))) {
                        stations.add(station);
                    }
                }
            }
            return stations;
        }
    }

你没有解释哪些项目显示哪些不显示。

我猜总是只显示前 N 项。 #query() 方法的第二个参数是 int page (在您的代码中命名为 i )。此参数应用于对结果进行分页。 IE。你不应该总是 return 10000 件物品并让 JavaScript 来处理它们,但你必须 return 0-20、21-40、41-60 等