ligerUI---ListBox(列表框可移動),

來源:互聯網
上載者:User

ligerUI---ListBox(列表框可移動),

寫在前面:

  對於可移動的列表框,ligerui中也對其進行了封裝,可以直接照著demo拿來用,不過那都是直接在頁面上靜態初始化的資料,那麼如何從後台擷取?

前面有了對ligerui的一些組件的使用經驗後,在這裡其實 對於從後台擷取資料在前台頁面進行顯示,都大同小異。也不是很難。

  即要麼是在ligerui組件中直接使用其url屬性向後台發送請求,要麼是單獨發送一個ajax請求拿到資料後,通過擷取組件,然後設定其data屬性。嘿嘿。。

下面就直接使用url屬性來發送請求吧。。。。。

 

前台頁面:

 

<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 >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)的時候已經寫過了,就不再重複說了

效果示範:(省略向左向右的移動)

在不勾選資料的情況下,點擊“點擊”按鈕,的如下:

 

其實在移除的過程中,一開始使用的removeItems()方法,但是測試貌似不可以移除,故採用removeItem()的方法,根據id來移除。。

額呃呃呃呃呃呃呃呃呃。。今天不用加班啦。。開心。。。。。。。。。。。。。。。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.