Logbook webroot--edit page about processing two associations selection box

Source: Internet
Author: User

Case: Click Edit, after the popup interface each column has a default value, but if one of the selection box changes, trigger the data in the other selection box changes (such as organizational selection changes, the corresponding organization of the subordinate agencies also change).

Solution: In the organizational function, when the selection changes, the value is triggered and passed to the subordinate mechanism function. In the normal operation of the organization function, it triggers and passes the value to the subordinate mechanism function.

Organizational functions

functionsetorganization (id,paramsor) {varType= "organization";varparams = {"token": GetStorage ("token"), "flag": 1};varFullurl=getoption ("gykj_host") + "organization/list" + "?" +getoption ("Gykj_callbackparam") + "=" +getoption ("Gykj_callbackfunc");//$ (' #submenu_info '). HTML (fullurl);$.ajax ({url:fullurl, type:' Get ', DataType:"Jsonp", Jsonp:getoption ("Gykj_callbackparam"), Jsonpcallback:getoption ("Gykj_callbackfunc"), Async:false, Error:function() {alert ("List:" +getoption ("Connectionerrormessage")); }, Success:function(data) {if(Data.resultcode==getoption ("Resultcode_success")){                                varHtml= ' <select class= "Chosen-select form-control" id= "o_id" data-placeholder= "Select an organizational Structure ..." > ";  for(varIteminchdata.data) {                    //var organization = {"O_ID": data.data[item].o_id, "O_name":d ata.data[item].o_name, "logo":d Ata.data[item].logo, " Description ": data.data[item].description," flag ": 1};                    //alert (data.data[item].organization);                    varStr=json.stringify (Data.data[item]); HTML+ = "<option value=" "+str+" "; if(data.data[item].o_id!=NULL&&paramsor[' organization ']!=NULL&&data.data[item].o_id==paramsor[' organization '].o_id) {html+ = "Selected"; } HTML+ = ">" +data.data[item].o_name+ "</option>"; } HTML+ = "</select>"; $("#organizations"). HTML (HTML); varoid=paramsor[' organization '].o_id; $(' #o_id '). Change (function(){//If the organization changes                    varorganizationstr=$ (' #o_id '). Val (); varobj=Json.parse (ORGANIZATIONSTR); OID=obj.o_id; Setmachinegroup (oid,paramsor);//the organization ID that passes and triggers the change to the subordinate agency                                    }); }Else{alert ("Error code" +data.errorcode+ ":" +data.message); }        varNullid= ""; Setmachinegroup (nullid,paramsor);//pass and trigger an unchanged organizational ID to the subordinate organization    }        }); }

Subordinate mechanism functions

functionSetmachinegroup (oid,paramsor) {varType= "Machinegroup";varparams = {"token": GetStorage ("token"), "flag": 1};if(oid== "") {//determine the value of the transfer if the ODI is empty, the default subordinate organization data is read    varFullurl=getoption ("Gykj_host") +type+ "/list" + "?" +getoption ("Gykj_callbackparam") + "=" +getoption ("Gykj_callbackfunc") + "&token=" +getstorage ("token");}Else{//otherwise, the corresponding subordinate organization data after the change of organizational structure    varFullurl=getoption ("Gykj_host") +type+ "/list" + "?" +getoption ("Gykj_callbackparam") + "=" +getoption ("Gykj_callbackfunc") + "&o_id=" +oid+ "&token=" +getStorage ( "Token");} $.ajax ({url:fullurl, type:' Get ', DataType:"Jsonp", Jsonp:getoption ("Gykj_callbackparam"), Jsonpcallback:getoption ("Gykj_callbackfunc"), Async:false, Error:function() {alert ("List:" +getoption ("Connectionerrormessage")); }, Success:function(data) {if(Data.resultcode==getoption ("Resultcode_success")){                                    varHtml= ' <select class= "Chosen-select form-control" id= "mg_id" data-placeholder= "Select a terminal group ..." ><option value= " "></option>";  for(varIteminchdata.data) {                        //var machinegroup = {"mg_id": data.data[item].mg_id, "Mg_name":d ata.data[item].mg_name, "description": data.data[ Item].description, "flag": 1};                        varMachinegroup_str=json.stringify (Data.data[item]); HTML+ = "<option value=" "+machinegroup_str+" "; if(data.data[item].mg_id!=NULL&&paramsor[' Machinegroup ']!=NULL&&data.data[item].mg_id==paramsor[' Machinegroup '].mg_id) {html+ = "Selected"; } HTML+ = ">" +data.data[item].mg_name+ "</option>"; } HTML+ = "</select>"; $("#machinegroup"). HTML (HTML);                                                                    Setsupplier (Paramsor); //$ (' #mg_id '). Chosen ({allow_single_deselect:true});                                }Else{alert ("Error code" +data.errorcode+ ":" +data.message); //$ ("#machinegrouptype"). HTML ("");            }                    }            }); }

Logbook webroot--edit page about processing two associations selection box

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.