function formatRepo (repo) {
return repo.name+"("+repo.eng+")";
}
$(document).ready(function () {
$("#companyId").select2({
ajax: {
url: "${base}/platform/yc/product/company",
dataType: 'json',
delay: 250,
data: function (params) {
return {
name: params.term,
page: params.page
};
},
processResults: function (data, params) {
params.page = params.page || 1;
return {
results: data.items,
pagination: {
more: (params.page * 30) < data.total_count
}
};
},
cache: true
},
escapeMarkup: function (markup) {
return markup;
},
minimumInputLength: 1,
templateResult: formatRepo
});
});
@At
@Ok("json")
public Object company(@Param("name") String name, @Param("page") int page) {
NutMap map = NutMap.NEW();
Pager pager = new Pager();
pager.setPageNumber(page);
pager.setPageSize(30);
List<Yc_company> list = ycCompanyService.query(Cnd.where("name", "like", "%" + name + "%").or("short_name", "like", "%" + name + "%").or("eng_name", "like", "%" + name + "%"), pager);
List<NutMap> mapList = new ArrayList<>();
for (Yc_company company : list) {
mapList.add(NutMap.NEW().addv("id", company.getId()).addv("text", company.getName()).addv("eng", company.getEng_name()).addv("name", company.getName()));
}
map.addv("page", page);
map.addv("total_count", pager.getRecordCount());
map.addv("items", mapList);
return map;
}
<select type="text" id="companyId" name="companyId" data-parsley-required="true"
class="form-control"></select>