当前位置:网站首页>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
边栏推荐
- Middle and rear binary tree
- Use split to solve the "most common words" problem
- 使用DFS来解决“字典序排数”问题
- C语言实现通讯录----(静态版本)
- PID debugging of coding motor (speed loop | position loop | follow)
- 2022 P cylinder filling training test questions and simulation test
- Laravel8- use JWT
- Recursion - outputs continuously increasing numbers
- The most detailed in the whole network, software testing measurement, how to optimize software testing cost and improve efficiency --- hot
- The backtracking of stack is used to solve the problem of "the longest absolute path of file"
猜你喜欢
“如何实现集中管理、灵活高效的CI/CD”在线研讨会精彩内容分享
The whole network is the most complete. How to do interface automation test? Proficient in interface automation test details
Recommend reading | share the trader's book list and ask famous experts for trading advice. The trading is wonderful
Mise en service PID du moteur de codage (anneau de vitesse | anneau de position | suivant)
Xutils3 corrected a bug I reported. Happy
Realize QQ login with PHP
The most easy to understand dependency injection and control inversion
xutils3修改了我提报的一个bug,开心
svg标签中利用<polygon/>循环数组绘制多边形
2022 Shandong Province safety officer C certificate work certificate question bank and online simulation examination
随机推荐
交换二叉树中每个结点的左和右
How does Microsoft solve the problem of multiple PC programs
2022t elevator repair test simulation 100 questions and online simulation test
利用栈的回溯来解决“文件的最长绝对路径”问题
2022 Shandong Province safety officer C certificate work certificate question bank and online simulation examination
建立与遍历二叉树
Use of metagroup object tuple in C
Distributed system services
Tencent video VIP member, weekly card special price of 9 yuan! Tencent official direct charging, members take effect immediately!
一文了解全面静态代码分析
Top 9 task management system in 2022
Load view Caton
2022年做跨境电商五大技巧小分享
Judge whether there is a leap year in the given year
c#语法糖模式匹配【switch 表达式】
Response processing of openfeign
xutils3修改了我提报的一个bug,开心
After the mobile phone is connected to the computer, how can QT's QDIR read the mobile phone file path
MYSQL_ From mastery to abandonment
Fundamentals of software testing and development