Copy codeThe Code is as follows:
$ (Document). ready (function (){
$ ("# Precinct"). change (function (){
$ ("# Ptype"). val (""); // reset all
$ ("# Stype" ).html ("");
$ ("# Stype"). append ("<option value = \" \ "> -- select -- </option> ");
});
<Span style = "white-space: pre"> </span> // listen to the change event of the patent type
$ ("# Ptype"). change (function (){
Var ptype = $ (this );
Var atype = $ (this). val (); // object Value
Var pid = $ ("# precinct"). val ();
If (! Ptype. data (atype) {// get the value from the cache and do not need to interact with the server.
$. Post ("Main/PatentSubsidy/getSubsidy", {askfor: atype, precinct: pid}, function (json) {// return a json object
$ ("# Stype" ).html (""); // clear <span style = "font-family: Arial, Helvetica, sans-serif; "> # stype </span> drop-down list
For (var I = 0; I <json. length; I ++ ){
// Add
$ ("# Stype "). append ("<option value = '" + json [I]. id + "'>" + json [I]. value + "</option> ");
};
Ptype. data (atype, json); // Add the key with the # ptype value to the cache
}, 'Json ');
} Else {
Var json = ptype. data (atype); // retrieves the cache
$ ("# Stype" ).html ("");
For (var I = 0; I <json. length; I ++ ){
// Add
$ ("# Stype "). append ("<option value = '" + json [I]. id + "'>" + json [I]. value + "</option> ");
};
}
});
});
Obtained according to # precinct and # ptype # stype
Action method
Copy codeThe Code is as follows:
Public void getSubsidy (){
String askfor = null, precinct = null;
If (null! = GetPara ("askfor ")&&! "". Equals (getPara ("askfor "))){
Askfor = getPara ("askfor ");
If (null! = GetPara ("precinct ")&&! "". Equals (getPara ("precinct "))){
Precinct = getPara ("precinct ");
}
} Else {
RenderJson ("[{\" id \ ": \" \ ", \" value \ ": \" -- select -- \ "}]"); // pass null values, return
}
String SQL = "select s. id, s. subsidy_type, p. name from org_subsidy_flow s, tab_precinct p where s. enabled = 'true' and p. status = '1' and s. patent_type = '"+ askfor +"' and s. precinct = p. id ";
If (null! = Precinct &&! "". Equals (precinct )){
SQL + = "and p. id =" + precinct;
}
SQL + = "order by p. id, s. id ";
List <Org_subsidy_flow> sf = Org_subsidy_flow.dao.find (SQL );
If (sf. size ()! = 0 ){
StringBuffer buffer = new StringBuffer ();
For (int I = 0; I <sf. size (); I ++ ){
Buffer. append ("{\" id \ ": \" "+ sf. get (I ). getInt ("id") + "\", \ "value \": \ "" + sf. get (I ). getStr ("subsidy_type") + "--" + sf. get (I ). getStr ("name") + "\"},");
}
If (buffer. length ()! = 0 ){
RenderJson ("[" + buffer. substring (0, buffer. length ()-1). toString () + "]");
}
} Else {
RenderJson ("[{\" id \ ": \" \ ", \" value \ ": \" -- select -- \ "}]");
}
}