ligerUI中ListBox列表框可移动的示例分析

发布时间:2021-07-23 13:42:52 作者:小新
来源:亿速云 阅读:238

这篇文章将为大家详细讲解有关ligerUI中ListBox列表框可移动的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

前台页面:

<script type="text/javascript">
 var box1,box2;

 $(function() {

  //初始化8个listbox
  box1 = $("#listbox1").ligerListBox({
   isShowCheckBox: true,
   isMultiSelect: true,
   height: 140,
   //发送给后台的请求
   url: '${baseURL}/getDeviceByAll.action',
  });
  box2 = $("#listbox2").ligerListBox({
   isShowCheckBox: true,
   isMultiSelect: true,
   height: 140,

  });

  var tempData2 = [{id:1,text:"aa"},{id:2,text:"bb"}];

  //button点击事件
  $("#btn1").click(function(){
   setListBoxData(tempData2);
  });

 });



 function setListBoxData(tempData2){
  //貌似只能通过id来移除了 用removeItems不可以达到效果
  //例如移除id为1,2的然后添加到左边
  for(var i=0;i<tempData2.length;i++){
   box1.removeItem(tempData2[i].id);
  }
  box2.addItems(tempData2);
 }

 //===========listbox四个按钮点击相关函数===========
 function moveToLeft1()
 {
  var selecteds = box2.getSelectedItems();
  if (!selecteds || !selecteds.length) return;
  box2.removeItems(selecteds);
  box1.addItems(selecteds);

 }

 function moveToRight1()
 {
  var selecteds = box1.getSelectedItems();
  if (!selecteds || !selecteds.length) return;
  box1.removeItems(selecteds);
  box2.addItems(selecteds);


 }
 function moveAllToLeft1()
 {
  var selecteds = box2.data;
  if (!selecteds || !selecteds.length) return;
  box1.addItems(selecteds);
  box2.removeItems(selecteds);

 }
 function moveAllToRight1()
 {
  var selecteds = box1.data;
  if (!selecteds || !selecteds.length) return;
  box2.addItems(selecteds);
  box1.removeItems(selecteds);

 }




</script>
<style type="text/css">
 .middle input {
  display: block;width:30px; margin:2px;
 }
</style>
</head>
<body>

  <div>
   <div >Support Devices:</div>
   <div >
    <div id="listbox1"></div>
   </div>
   <div  class="middle">
    <input type="button" onclick="moveToLeft1()" value="<" />
    <input type="button" onclick="moveToRight1()" value=">" />
    <input type="button" onclick="moveAllToLeft1()" value="<<" />
    <input type="button" onclick="moveAllToRight1()" value=">>" />
   </div>
   <div >
    <div id="listbox2"></div>
   </div>
  </div>

  <input type="button" value="点击" id="btn1">


</body>

后台action:

private JSONArray jsonArray;
 public JSONArray getJsonArray() {
  return jsonArray;
 }
 public String getDeviceByAll() throws Exception{
  List<Device> deviceList = deviceService.getAll(Device.class);

  jsonArray = new JSONArray();
  for(Device device:deviceList){
   JSONObject obj = new JSONObject();
   //listbox对应的数据格式要有text、id字段
   obj.put("id",device.getDevId());
   obj.put("text",device.getDevName());
   jsonArray.add(obj);

  }
  return SUCCESS;
 }

好啦,这样就成功了,当然 我这里是省略了后台如何将json数据传递到前台,因为在我写ligerui的其他组件(ligerGrid,ligerForm)的时候已经写过了,就不再重复说了

效果演示截图:(省略向左向右的移动效果图)

ligerUI中ListBox列表框可移动的示例分析

在不勾选数据的情况下,点击“点击”按钮,的效果图如下:
ligerUI中ListBox列表框可移动的示例分析

其实在移除的过程中,一开始使用的removeItems()方法,但是测试貌似不可以移除,故采用removeItem()的方法,根据id来移除。。

关于“ligerUI中ListBox列表框可移动的示例分析”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

推荐阅读:
  1. LigerUI的简单使用示例
  2. 30、C#里面的列表框:ListBox的使用

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ligerui listbox

上一篇:CheckBox多选取值及判断CheckBox选中是否为空的示例分析

下一篇:jar包与was版本不兼容如何解决

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》