ligerUI---ListBox(列表框可移動的實例)
寫在前面:
對于可移動的列表框,ligerui中也對其進(jìn)行了封裝,可以直接照著demo拿來用,不過那都是直接在頁面上靜態(tài)初始化的數(shù)據(jù),那么如何從后臺獲???
前面有了對ligerui的一些組件的使用經(jīng)驗后,在這里其實 對于從后臺獲取數(shù)據(jù)在前臺頁面進(jìn)行顯示,都大同小異。也不是很難。
即要么是在ligerui組件中直接使用其url屬性向后臺發(fā)送請求,要么是單獨發(fā)送一個ajax請求拿到數(shù)據(jù)后,通過獲取組件,然后設(shè)置其data屬性。嘿嘿。。
下面就直接使用url屬性來發(fā)送請求吧。。。。。
前臺頁面:
<script type="text/javascript"> var box1,box2; $(function() { //初始化8個listbox box1 = $("#listbox1").ligerListBox({ isShowCheckBox: true, isMultiSelect: true, height: 140, //發(fā)送給后臺的請求 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不可以達(dá)到效果 //例如移除id為1,2的然后添加到左邊 for(var i=0;i<tempData2.length;i++){ box1.removeItem(tempData2[i].id); } box2.addItems(tempData2); } //===========listbox四個按鈕點擊相關(guān)函數(shù)=========== 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 style="float:left;font-size:15px;width:150px;text-align: center">Support Devices:</div> <div style="margin:4px;float:left;"> <div id="listbox1"></div> </div> <div style="margin:4px;float:left;" 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 style="margin:4px;float:left;"> <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對應(yīng)的數(shù)據(jù)格式要有text、id字段 obj.put("id",device.getDevId()); obj.put("text",device.getDevName()); jsonArray.add(obj); } return SUCCESS; }
好啦,這樣就成功了,當(dāng)然 我這里是省略了后臺如何將json數(shù)據(jù)傳遞到前臺,因為在我寫ligerui的其他組件(ligerGrid,ligerForm)的時候已經(jīng)寫過了,就不再重復(fù)說了
效果演示截圖:(省略向左向右的移動效果圖)
在不勾選數(shù)據(jù)的情況下,點擊“點擊”按鈕,的效果圖如下:
其實在移除的過程中,一開始使用的removeItems()方法,但是測試貌似不可以移除,故采用removeItem()的方法,根據(jù)id來移除。。
相關(guān)文章
django admin 使用SimpleUI自定義按鈕彈窗框示例
Django 后臺admin有大量的屬性和方法,擁有強大的功能和自定義能力,這篇文章主要介紹了django admin 使用SimpleUI自定義按鈕彈窗框示例,需要的朋友可以參考下2023-04-04JavaScript設(shè)計模式之工廠模式和構(gòu)造器模式
這篇文章主要介紹了JavaScript設(shè)計模式之工廠模式和構(gòu)造器模式,本文同時講解了設(shè)計模式的類別如創(chuàng)建型設(shè)計模式、結(jié)構(gòu)型設(shè)計模式、行為設(shè)計模式等內(nèi)容,需要的朋友可以參考下2015-02-02利用uni-app和uView實現(xiàn)多圖上傳功能全過程
最近在使用uniapp開發(fā)的微信小程序中使用了圖片上傳功能,下面這篇文章主要給大家介紹了關(guān)于利用uni-app和uView實現(xiàn)多圖上傳功能的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-03-03微信小程序登錄方法之授權(quán)登陸及獲取微信用戶手機(jī)號
最近改了一個公司項目,新增加了一個獲取用戶手機(jī)號功能,里面用到了關(guān)于獲取用戶信息和用戶手機(jī)號的功能,下面這篇文章主要給大家介紹了關(guān)于微信小程序登錄方法之授權(quán)登陸及獲取微信用戶手機(jī)號的相關(guān)資料,需要的朋友可以參考下2022-07-07Bootstrap入門教程一Hello Bootstrap初識
Bootstrap,來自 Twitter,是目前很受歡迎的前端框架。Bootstrap是基于 HTML5、CSS3和Javascriopt開發(fā)的。這篇文章主要介紹了基于Bootstrap3實現(xiàn)漂亮簡潔的CSS3價格表(精美代碼版),需要的朋友可以參考下2017-03-03