jquery + json 动态创建复杂表格table

2022-05-09 12:03:58 浏览数 (1)

代码语言:javascript复制
    function SetSubTable() {
        var obj = jQuery.parseJSON($("#SubJsonStrValue").val());
        window.ALLPARAMTERS = obj;
        var row_str = "";
        var span_num = 1
        for (var i = 0; i < obj.length; i  ) {
            if (obj[i].ParamNames.length > 0) {
                row_str  = '<tr><td rowspan="'   obj[i].ParamNames.length   '"><input type="checkbox" name="_' obj[i].Id '" />'   obj[i].Name   '</td>';
                for (var j = 0; j < obj[i].ParamNames.length; j  ) {
                    if (j != 0) {
                        row_str  = "<tr>";
                    }
                    row_str  = '<td><input type="checkbox" name="p_' obj[i].ParamNames[j].Id '_' obj[i].Id '" />'   obj[i].ParamNames[j].Name   '</td><td>';
                    for (var k = 0; k < obj[i].ParamNames[j].ListItems.length; k  ) {
                        row_str  = obj[i].ParamNames[j].ListItems[k].Name "|";
                    }
                    row_str = row_str.substring(0, row_str.length - 2);
                    row_str  = "</td><td>";
                    if (obj[i].ParamNames[j].CanMultiSelecte) {
                        row_str  = "多选";
                    } else {
                        row_str  = "单选";
                    }
                    row_str  = "</td></tr>";
                }
            }
        }
        $("#sub_table_header").after(row_str);
    }

0 人点赞