LigerUI --- ListBox (the list box is movable ),

Source: Internet
Author: User

LigerUI --- ListBox (the list box is movable ),

Preface:

  Ligerui also encapsulates a removable list box, which can be used directly according to the demo. However, it is static initialization data directly on the page. How can this problem be obtained from the background?

With the previous use experience of some ligerui components, it is almost the same to display the data obtained from the background on the front-end page. It is not very difficult.

That is, you can either directly send a request to the background using its url attribute in the ligerui component, or send an ajax request separately to obtain the data, obtain the component, and set its data attribute. Hey ..

Next we will directly use the url attribute to send the request .....

 

Front-end page:

 

<Script type = "text/javascript"> var box1, box2; $ (function () {// initialize eight listbox box1 =$ ("# listbox1 "). ligerListBox ({isShowCheckBox: true, isMultiSelect: true, height: 140, // The request url sent to the background: '$ {baseURL}/getDeviceByAll. action ',}); box2 = $ ("# listbox2 "). ligerListBox ({isShowCheckBox: true, isMultiSelect: true, height: 140,}); var tempData2 = [{id: 1, text: "aa"}, {id: 2, text: "bb"}]; // button click event $ ("# btn1 "). c Lick (function () {setListBoxData (tempData2) ;}); function setListBoxData (tempData2) {// it seems that only the id can be used to remove the effect that removeItems cannot achieve. // for example, remove the id 1, 2 and add it to the left for (var I = 0; I <tempData2.length; I ++) {box1.removeItem (tempData2 [I]. id);} box2.addItems (tempData2 );} // ============== listbox click related functions ============= 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> 

 

Well, this will succeed. Of course, I omit how the background transmits json data to the foreground, because other components of ligerui (ligerGrid, ligerForm) I already wrote it, so I will not repeat it again.

Demo: (move left to right is omitted)

If data is not checked, click the "click" button, as shown in the following figure:

 

In fact, in the process of removal, the removeItems () method was used at the beginning, but the test does not seem to be able to be removed. Therefore, the removeItem () method is used to remove objects based on the id ..

Er er .. You don't have to work overtime today .. Happy ...............

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.