Selec2下拉列表未显示响应中的所有项目

问题描述 投票:0回答:1

我在选择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;
        }
    }
jquery-select2 wicket
1个回答
1
投票

您不解释显示哪些项目,哪些不显示。

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

© www.soinside.com 2019 - 2024. All rights reserved.