If a first-level rating item contains rating sub-items, when the rating item is clicked, a new window will pop up. The new form lists a list of all rating sub-items of the current rating item for the user to operate. After the user operation is completed, click the "OK" button to return to the parent form, and all operation results in the child form will be brought to the parent form at the same time. At the same time, if the user clicks the rating item again, while the subform pops up, the result of the last operation must be bound to the corresponding operation item.
The example described above involves data transfer between a parent and child forms. There are of course many ways to implement this data transfer. Here I just record the method I used in this example. My method is to construct the operation result into a string in json format when the subform clicks the "OK" button, and transfers the json format data to the parent form by calling the method on the parent form: opener.method() superior.
The json data constructed in this example is similar to 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"}
]}
The sub-item scores that need to be maintained are bh: number; lx: type; df: score; bz: remarks.
According to your own needs, you can add items that need to be maintained. This json data can be constructed in the foreground or in the background.
In this example, I placed the background. The 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 = "卐"; //This special symbol is used here 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 can be prevented after jsonBuilder.ToString() , the escape character "" disappears.
Call the GetZXDF() method of the parent form to pass the json data to the parent form.
The following is the code for binding json data when the subform is loaded
$(function() {
//Get json when loading, and then bind the scoring 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"){
//Direct classification binding Define
$("#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"){
//Binding of option classification
$(" #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);
}
});
opener.GetJson() method is used on the parent form to pass to the child form json data method, the code is as follows:
// Get the json string of the sub-item scoring result of the corresponding rating item by number
function GetJson(p_bh)
{
//$("#zxdf" p_bh ).siblings("input").eq(1).val() stores the json data passed from the child form to the parent form
return $("#zxdf" p_bh).siblings("input" ).eq(1).val();
}