当前位置:网站首页>EasyUI's combobox implements three-level query
EasyUI's combobox implements three-level query
2022-04-23 03:12:00 【A happy wild pointer D】
1、 Business needs
Select a dormitory building , Then choose a floor of the building , Then choose a bedroom on this floor
2、 Realize the idea
First query the list of dormitory buildings from the database , Initialize the combo box of the dormitory building , Let the user choose one of them , After choosing, transfer the building to the backstage , Let the background find out which floors the building has according to this value , Fill the query results into the combo box of the floor , After the user selects again, the floor and dormitory building will be returned to the background , The background queries the building according to these two parameters 、 All dormitories on this floor
3、 The front-end code
<div>
<span> Dormitory building </span>
<input id="bid" class="easyui-combobox" name="bid"
data-options="
url:'${pageContext.request.contextPath}/getbid.action',// Background method of loading dormitory data
method:'get',
valueField:'id',
textField:'text',
editable:false,
// When a user selects an item , Trigger this event ,rec For the user's current selection
onSelect:function(rec){
var bid=rec.text;// Value
$('#floor').combobox('clear');// Clear the option of the previous floor
// Background method of loading floor data , Splice parameters to url On
var url='${pageContext.request.contextPath}/getfloor.action?bid='+bid;
$('#floor').combobox('reload',url);// Reload the data of the floor
}" />
<span> floor </span>
<input id="floor" class="easyui-combobox" name="floor"
data-options="
valueField:'id',
textField:'text',
editable:false,
onSelect:function(rec){
var bid=$('#bid').combobox('getValue');
var floor=rec.text;
// Clear the previous dormitory options
$('#room').combobox('clear');
// Background method of loading dormitory , Splice parameters to url On
var url='${pageContext.request.contextPath}/getroom.action?bid='+bid+'&floor='+floor;
$('#room').combobox('reload',url);// Reload
}" />
<span> dormitory </span>
<input id="room" class="easyui-combobox" name="room"
data-options="
valueField:'id',
textField:'text',
editable:false
" />
<a id="search-btn" href="javascript:;" class="easyui-linkbutton" plain="true" iconCls="icon-search"> Inquire about </a>
</div>
of no avail JavaScript Assign your own... To the floor and dormitory number url Because my floor and dormitory must have parameters , If in script The... They load is given in url, When the page is loaded, it will automatically go to the background to execute the method , But at this time, the dormitory building has not chosen , Therefore, there are no parameters , Browser's console You're going to report a mistake , Cause the program cannot continue to execute
4、 Background code
controller
/**
* Check all dormitory buildings
* @return
*/
@RequestMapping(value="/getbid.action")
@ResponseBody
public List<ComboboxModel> getBid()
{
List<ComboboxModel> models=new ArrayList<>();
List<String> list = dormManageService.getRDbidType();
for (String item : list) {
models.add(new ComboboxModel(item,item));
}
System.out.println(models.toString());
return models;
}
/**
* Query the number of floors of the selected dormitory building
* @param bid Selected dormitory building
* @return
*/
@RequestMapping(value="/getfloor.action")
@ResponseBody
public List<ComboboxModel> getFloor(@RequestParam("bid")String bid)
{
List<ComboboxModel> models=new ArrayList<>();
List<String> list = dormManageService.getRDfloorType(bid);
for (String item : list) {
models.add(new ComboboxModel(item,item));
}
System.out.println(models.toString());
return models;
}
/**
* Query the dormitory number of the selected floor
* @param bid Selected dormitory building
* @param floor Selected floor
* @return
*/
@RequestMapping(value="/getroom.action")
@ResponseBody
public List<ComboboxModel> getRoom(@RequestParam("bid")String bid,@RequestParam("floor") String floor)
{
List<ComboboxModel> models=new ArrayList<>();
List<String> list = dormManageService.getRDroomType(bid, floor);
for (String item : list) {
models.add(new ComboboxModel(item,item));
}
System.out.println(models.toString());
return models;
}
Specifically for combobox Built for pojo
package com.pojo;
public class ComboboxModel {
private String id;// Used as a combobox Of value
private String text;// Used as a combobox Of text
public ComboboxModel() {
super();
}
public ComboboxModel(String id, String text) {
super();
this.id = id;
this.text = text;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
@Override
public String toString() {
return "ComboboxModel [id=" + id + ", text=" + text + "]";
}
}
版权声明
本文为[A happy wild pointer D]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220627538442.html
边栏推荐
- Recommend reading | share the trader's book list and ask famous experts for trading advice. The trading is wonderful
- 使用split来解决“最常见的单词”问题
- Blazor University (12) - component lifecycle
- The most easy to understand dependency injection and control inversion
- TP5 multi conditional where query (using PHP variables)
- 类似Jira的十大项目管理软件
- Judge whether there is a leap year in the given year
- 由于3²+4²=5²,所以称‘3,4,5‘为勾股数,求n(包括n)以内所有勾股数数组。
- C syntax pattern matching [switch expression]
- MAUI初体验:爽
猜你喜欢

The most easy to understand service container and scope of dependency injection

基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客?

Ide-idea-problem

C read / write binary file

【无标题】

Maui initial experience: Cool

Xamarin effect Chapter 21 expandable floating operation button in GIS

《C语言程序设计》(谭浩强第五版) 第7章 用函数实现模块化程序设计 习题解析与答案

Aspnetcore configuration multi environment log4net configuration file

ASP. Net and ASP NETCORE multi environment configuration comparison
随机推荐
LNMP MySQL allows remote access
OLED multi-level menu record
Array and collection types passed by openfeign parameters
[MySQL] left Function | Right Function
[MySQL] left function | right function
搭建XAMPP时mysql端口被占用
Recommend reading | share the trader's book list and ask famous experts for trading advice. The trading is wonderful
C语言实现通讯录----(静态版本)
[new version release] componentone added Net 6 and blazor platform control support
Xutils3 corrected a bug I reported. Happy
准备一个月去参加ACM,是一种什么体验?
Mise en service PID du moteur de codage (anneau de vitesse | anneau de position | suivant)
Top 9 task management system in 2022
Detailed log display of openfeign call
全网讲的最细,软件测试度量,怎样优化软件测试成本提高效率---火爆
be based on. NETCORE development blog project starblog - (2) environment preparation and creation project
Mysql database design specification
Middle and rear binary tree
使用两种方法来解决“最大回文数乘积”问题
利用正反遍历来解决“字符的最短距离”问题