LigerUI --- use the drop-down box in ligerForm,
Preface:
LigerUI is used in the front frame of the recent project. At first, I refused to use ligerUI, because it seems that ligerUI is rarely used, I really want to ask our team's Brother Bin why ligerUI is used as the front-end framework ????? LigerUI has never been used. Alas, it is really annoying to do so, because no one can help, and most of the demos of the official website APIs obtain data locally, but we certainly don't get local data, but get data from the background .. You can only watch the api and demo slowly .... Okay. I have made the module. Ah, haha ..... (I am also very grateful to those who have helped me in the course of my work. I have to say that sometimes others are not obligated to help you solve a very simple problem, even in the eyes of others, I added a ligerUI group with 400 or 500 people in it. I asked questions and replied to none of them... The world is cool .. But helping others ....)
For the drop-down box in ligerForm, the url first sends a request to the background for data retrieval in the background, and then converts the request to the corresponding json format corresponding to the json format, the important thing is said three times. The code is simple and clear ..
1. Front-end Page code:
Form1 = $ ("# form1 "). ligerForm ({inputWidth: 170, labelWidth: 100, space: 15, labelAlign: 'right', validate: true, fields: [{id: 'systemselect', type: 'select', display: 'system', newline: true, name: 'systemid', // when you want to obtain the value in the drop-down box, use // liger. get ("comboboxName "). getValue (); comboboxName: 'systemselect', options: {// request url sent to the background: '$ {baseURL}/listAllSystem. action ', // The id field valueField: 'System Id', // The textField: 'systemname', onSelected: function (newvalue) {// select the drop-down box event... },},},] ,});
2. Background code:
@ Controller ("SystemAction") public class SystemAction extends ActionSupport {// inject service layer interface @ Resource private SystemService systemService; // arr in json format returned by struts2 can be received by the page // A get method is required. private JSONArray arr; public JSONArray getArr () {return arr ;} public String listAllSystem () {List <System> systemList = systemService. getAll (System. class); arr = new JSONArray (); for (System sys: systemList) {JSONObject obj = new JSONObject (); obj. put ("systemId", sys. getSystemId (); obj. put ("systemName", sys. getSystemName (); arr. add (obj);} java. lang. system. out. println (arr. toString (); // [{"systemId": 1, "systemName": "USM" },{ "systemId": 2, "systemName": "DMS "}, {"systemId": 3, "systemName": "LOL"}] // The Data printed in the background is as follows: systemId, systemName must correspond to return "system_list";} on the front-end page ";}}
Do not think that as long as the data returned in the background action is in json format, you can directly obtain the data on the foreground page and then display it. That is impossible.
The front-end can receive data in the json format in the background, which must be processed as follows:
1. First, the json format data returned by your background should correspond to the field content displayed in the drop-down box of your foreground page:
2.
2. Configure the result set view returned by struts2 to set type = json (the struts2 framework is used here, so the struts2 framework is used as an example)
<Action name = "listAll *" class = "{1} Action" method = "listAll {1}"> <result name = "system_list" type = "json"> <! -- Set the data source to get from a specific data. Here is arr --> <param name = "root"> arr </param> </result> </action>
3. Set the package of the corresponding action to inherit from json-default.
<package name="fums" namespace="/" extends="struts-default,json-default">
4. Provide the get method for the data to be returned in the background action
5. Set the format of the returned data in struts. xml (see the code in step 1, that is, the <param> section)
Okay .. With this, we will succeed .... Ah, haha