dojo:如何用MultiSelect实现类似ListBox风格的FromTo功能
欲实现的功能如下图:

主要要解决的问题包括两个方面:
一个是MultiSelet初始化的工作,一个是FromTo功能按钮的实现。这主要是因为MultiSelect控件是存储无关的,并不像Select或者Combobox那样好用。
下面简单说下流程:
step1: HTML部分
<table align="center">
<tr>
<td >
<fieldset>
<legend><font color="red"><b>配置管理</b></font></legend>
<table align="center">
<tr>
<td><select id="fromConfigSelect" ></select></td>
<td>
<input type="button" id="fromConfigButton" value=">>" /><br>
<input type="button" id="toConfigButton" value="<<" /><br>
</td>
<td><select id="toConfigSelect" ></select></td>
</tr>
</table>
</fieldset>
</td> <td >
<fieldset>
<legend><font color="red"><b>人员管理</b></font></legend>
<table align="center">
<tr>
<td><select id="fromHumanSelect" ></select></td>
<td>
<input type="button" id="fromHumanButton" value=">>" /><br>
<input type="button" id="toHumanButton" value="<<" /><br>
</td>
<td><select id="toHumanSelect" ></select></td>
</tr>
</table>
</fieldset>
</td> </tr>
<tr>
<td >
<fieldset>
<legend><font color="red"><b>供应管理</b></font></legend>
<table align="center">
<tr>
<td><select id="fromSupplySelect" ></select></td>
<td>
<input type="button" id="fromSupplyButton" value=">>" /><br>
<input type="button" id="toSupplyButton" value="<<" /><br>
</td>
<td><select id="toSupplySelect" ></select></td>
</tr>
</table>
</fieldset>
</td> <td >
<fieldset>
<legend><font color="red"><b>维修管理</b></font></legend>
<table align="center">
<tr>
<td><select id="fromMaintainSelect" ></select></td>
<td>
<input type="button" id="fromMaintainButton" value=">>" /><br>
<input type="button" id="toMaintainButton" value="<<" /><br>
</td>
<td><select id="toMaintainSelect" ></select></td>
</tr>
</table>
</fieldset>
</td>
</tr>
<tr></tr>
<tr></tr>
</table>
step2:MultiSelect初始化(以配置管理为例),其中下拉框的数据是从服务器端请求获得
//配置管理下拉框
var fromConfig,multiFromConfig;
var storeFromConfig;
request.get("roleInputGetJsonAction.action?mode=query&roleInput.fromSelect=config",{handleAs : "json"})//向服务器查询对应于WBS的设备名
.then(function(data){
storeFromConfig=new Memory({ data: data });
// 创建配置管理的下拉框
fromConfig = dom.byId('fromConfigSelect');
index=0;
for(var item in storeFromConfig.data){
var option = Win.doc.createElement('option');
option.innerHTML=storeFromConfig.data[index].name;
option.value=storeFromConfig.data[index].id;
index++;
fromConfig.appendChild(option);
}
multiFromConfig = new MultiSelect({ name: 'multiFromConfig',
size:4,
style: "width: 180px;",}, fromConfig);
multiFromConfig.startup(); }); var toConfig,multiToConfig;
var storeToConfig;
storeToConfig=new Memory({ });
toConfig = dom.byId('toConfigSelect');
multiToConfig = new MultiSelect({ name: 'multiToConfig',
size:4,
style: "width: 180px;",}, toConfig);
multiToConfig.startup();
step3 : 按钮事件的处理程序
//删除Select所有子节点的函数,多个按钮都会用到
function removeAllChildren(multiSelectDomNode){
while (multiSelectDomNode.firstChild) {
var node=multiSelectDomNode.firstChild;
multiSelectDomNode.removeChild(node);
}
} //FromTo.从一个下拉框中选择数据移动到另一个下拉框
function removeAndAddSelect(from,to,fromMulti,toMulti,fromMemory,toMemory){
index=0;
var fromItems=fromMulti.value;//获取鼠标选中的节点(可以是多个节点,以数组的形式) for(var fi in fromItems){
var id=fromItems[index];
var item=fromMemory.get(id);
fromMemory.remove(id);
toMemory.add(item);
index++;
} index=0;
for(var item in fromMemory.data){
var option = Win.doc.createElement('option');
option.innerHTML=fromMemory.data[index].name;
option.value=fromMemory.data[index].id;
from.appendChild(option);
index++;
} index=0;
for(var item in toMemory.data){
var option = Win.doc.createElement('option');
option.innerHTML=toMemory.data[index].name;
option.value=toMemory.data[index].id;
to.appendChild(option);
index++;
} removeAllChildren(fromMulti.domNode);
fromMulti._fillContent(from);
removeAllChildren(toMulti.domNode);
toMulti._fillContent(to); } //fromConfigButton等按钮的事件处理程序
var fromConfigButton=dom.byId("fromConfigButton");
on(fromConfigButton, "click", function(evt){
removeAndAddSelect(fromConfig,toConfig,multiFromConfig,multiToConfig,storeFromConfig,storeToConfig);
});
var toConfigButton=dom.byId("toConfigButton");
on(toConfigButton, "click", function(evt){
removeAndAddSelect(toConfig,fromConfig,multiToConfig,multiFromConfig,storeToConfig,storeFromConfig);
});
由于MultiSelect无法直接和store关联,所以必须要写DOM的JS代码。
dojo:如何用MultiSelect实现类似ListBox风格的FromTo功能的更多相关文章
- dojo:如何显示ListBox风格的选择框
常见的选择框控件:Selelct.FilteringSelect和ComboBox都是下拉框风格,而不是ListBox风格. dojo还提供了一个dijit.form.MultiSelect控件可以解 ...
- bootstrap风格的multiselect插件——类似邮箱收件人样式
在开发颗粒云邮箱的过程中,遇到了一个前端的问题,就是邮箱收件人的那个multiselect的input输入框.不仅能够多选,还要能够支持ajax搜索,把联系人搜索出来.就是类似下面的这个东西: 网上找 ...
- 请教如何用 peewee 实现类似 django ORM 的这种查询效果。
本人新入坑的小白,如有不对的地方请包涵~~~! 在 django 中代码如下:模型定义: class Friends(models.Model): first_id = models.IntegerF ...
- js 实现类似php函数number_format的功能
今天同事在做一个功能的时候需要使用js来实现类似php函数number_format的功能,最后就有了下面的方法,可以实现了: /** * number_format * @param number ...
- SharePoint 2010 类似人人网站内信功能实施
简介:用SharePoint代码加实施的方式,完成类似人人网站内信功能,当然,实现的比较简单,样式也比较难看,只为给大家一个实施的简单思路,如有谬误,还请见谅.当然,还有就是截图比较长,当然为了让大家 ...
- MVC实现类似QQ的网页聊天功能-ajax(下)
此篇文章主要是对MVC实现类似QQ的网页聊天功能(上)的部分代码的解释. 首先说一下显示框的滚动条置底的问题: 结构很简单一个大的div(高度一定.overflow:auto)包含着两个小的div第一 ...
- springmvc+ztree v3实现类似表单回显功能
在做权限管理系统时,可能会用到插件zTree v3,这是一个功能丰富强大的前端插件,应用很广泛,如异步加载菜单制作.下拉选择.权限分配等.在集成SpringMVC中,我分别实现了zTree的添删改查, ...
- WPF MultiSelect模式下ListBox 实现多个ListBoxItem拖拽
WPF 的ListBox不支持很多常见的用户习惯,如在Explorer中用鼠标可以选择多项Item,并且点击已经选择的Item,按住鼠标左键可以将所有已选择Item拖拽到指定的位置.本文简单的实现了这 ...
- 如何用tomcat实现类似weblogic那样的热部署方式
平时weblogic部署程序包时一般是到控制台去部署,不需要重启. 相反之前用tomcat部署应用时,我一般都是把tomcat重启来完成程序包的更新或新包部署.但是这次要部署的应用有点多,大概10几个 ...
随机推荐
- Nginx相关链接
nginx+lua实现waf http://blog.oldboyedu.com/nginx-waf/ nginx慕课网 http://coding.imooc.com/class/121.html ...
- js继承中,原型属性的继承探究
最近研究了js的继承,看了幻天芒的文章http://www.cnblogs.com/humin/p/4556820.html#3947420,明白了最好是使用apply或call方法来实现继承. 已知 ...
- Python 数据处理库 pandas 入门教程
Python 数据处理库 pandas 入门教程2018/04/17 · 工具与框架 · Pandas, Python 原文出处: 强波的技术博客 pandas是一个Python语言的软件包,在我们使 ...
- js第一天学习内容
var a=12: var t=(- -a)-(a- -)+(a++)-(a++) console.log(a) t=-1: a=12: (- -a)=11-(a=11- -)=10+(a=10++) ...
- python day04作业
- 2017ICPC南宁赛区网络赛 Overlapping Rectangles(重叠矩阵面积和=离散化模板)
There are nnn rectangles on the plane. The problem is to find the area of the union of these rectang ...
- POJ 1065 Wooden Sticks (贪心)
There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The st ...
- python 基础5 初级函数
函数最重要的目的是方便我们重复使用相同的一段程序.将一些操作隶属于一个函数,以后你想实现相同的操作的时候,只用调用函数名就可以,而不需要重复敲所有的语句. def my_len(): def 关键字 ...
- 【转载】 Pytorch(0)降低学习率torch.optim.lr_scheduler.ReduceLROnPlateau类
原文地址: https://blog.csdn.net/weixin_40100431/article/details/84311430 ------------------------------- ...
- jQuery的事件
事件冒泡处理 使用event.stopPropagation();阻止事件冒泡 冒泡事件也可以使用return false来处理 并且 <script type="text/javas ...