If a level-1 score item contains a score item, a new window is displayed when you click this item. The new form lists all the score items of the current score item, for user operations. After the user completes the operation, click "OK" to return to the parent form. All the operation results in the child form must be taken to the parent form. If you click this score item again, bind the result of the last operation to the corresponding operation item while the subform is displayed.
The example described above involves data transmission between a parent-child form. There are certainly many ways to implement this data transfer. Here is just a record of the method I used in this example. My method is to construct the operation result into a json string when the subform clicks the "OK" button, by calling the method on the parent form: opener. method () to pass the json format data to the parent form.
The json data constructed in this example is in the following format:
{"MyData ":[
{"Bh": "111", "lx": "1", "df": "10", "bz": "aaa "},
{"Bh": "112", "lx": "2", "df": "20", "bz": "bbb "},
{"Bh": "113", "lx": "2", "df": "30", "bz": "ccc "}
]}
Here, the sub-item scores must be respectively bh: Number; lx: type; df: score; bz: remarks.
You can add items to be maintained as needed. The json data can be constructed on the foreground or the background.
In this example, I place it in the background. The Code is as follows:
Copy codeThe Code is as follows:
StringBuilder jsonBuilder = new StringBuilder ();
JsonBuilder. Append ("@{\"");
JsonBuilder. Append ("MyData ");
JsonBuilder. Append ("\":[");
Int k = bh. Split (','). Length + 1;
For (int I = 0; I <bh. Split (','). Length; I ++)
{
Tem + = "update KH_PFX set DF = '" + EncriptLib. encriptLib. encodeCode (Convert. toDouble (df. split (',') [I]. toString (). trim () + "',";
Tem + = "BZ = '" + bz. split (',') [I]. toString (). trim () + "', PFRXM ='" + Session ["XM"]. toString () + "',";
Tem + = "PFRBH = '" + Session ["YHBH"]. toString () + "', PFRQ = to_date ('" + DateTime. now. toShortDateString () + "', 'yyyy-MM-dd ')";
Tem + = "where BH = '" + bh. Split (', ') [I]. ToString (). Trim () + "'";
Tem + = "separator"; // use this special symbol to separate SQL statements.
JsonBuilder. append ("{\" bh \ ":" + "\" "+ bh. split (',') [I]. toString (). trim () + "\" "+ ",");
JsonBuilder. append ("\" lx \ ":" + "\" "+ lx. split (',') [I]. toString (). trim () + "\" "+ ",");
JsonBuilder. append ("\" df \ ":" + "\" "+ df. split (',') [I]. toString (). trim () + "\" "+ ",");
JsonBuilder. append ("\" bz \ ":" + "\" "+ bz. split (',') [I]. toString (). trim () + "\" "+ "},");
}
If (tem! = "")
{
JsonBuilder. Remove (jsonBuilder. Length-1, 1 );
JsonBuilder. Append ("]");
JsonBuilder. Append ("}");
Page. clientScript. registerClientScriptBlock (GetType (), "cg", "<Script> window. close (); opener. getZXDF ('zxdf "+ Request. queryString ["bh"]. toString () + "','" + parent_df.Text.Trim () + "','" + jsonBuilder. toString () + "', \" "+ tem +" \ "); </Script> ");
}
The "@" symbol prevents the Escape Character "\" from disappearing after jsonBuilder. ToString.
Call the GetZXDF () method of the parent form to pass json data to the parent form.
The following code binds json data when a subform is loaded:
Copy codeThe Code is as follows:
$ (Function (){
// Obtain json during loading and bind the score result
Var obj = opener. GetJson ($ ("# txt_YCBH"). val ());
If ($. trim (obj )! = ""){
Obj = "(" + obj + ")";
Obj = eval (obj );
Var data = obj. MyData;
$. Each (data, function (I, n ){
If (n. lx = "1 "){
// Bind a category directly
$ ("# Lx" + n. bh). siblings ("input"). eq (0). val (n. df );
$ ("# Lx" + n. bh). siblings ("input"). eq (1). val (n. df );
$ ("# Lx" + n. bh ). parent (). parent (). next (). children (). children ("textarea "). val (n. bz );
}
If (n. lx = "2 "){
// Bind the option to category
$ ("# Lx" + n. bh). siblings ("input: text"). eq (1). val (n. df );
$ ("# Lx" + n. bh). siblings ("input: checkbox"). each (function (){
If ($. trim ($ (this). val () = $. trim (n. df )){
$ (This). attr ("checked", true );
}
});
$ ("# Lx" + n. bh ). parent (). parent (). parent (). next (). children (). children ("textarea "). val (n. bz );
}
});
The opener. GetJson () method is used to transmit json data to the child form on the parent form. The Code is as follows:
Copy codeThe Code is as follows:
// Obtain the json string of the score result of the corresponding subitem by serial number
Function GetJson (p_bh)
{
// $ ("# Zxdf" + p_bh). siblings ("input"). eq (1). val () stores the json data that the child form passes to the parent form.
Return $ ("# zxdf" + p_bh). siblings ("input"). eq (1). val ();
}