MVC架构下将查询到的数据以表格形式展现出来

        var sqlstr = Createsqlstr(maxreturnrows);//sql语句
        var res = $("#result");
        res.empty();
        $("#result").css("display", "block");
        postAjax("Query",
            "ComplexDataQuery_get",
            sqlstr,
            function (json) {
                loadingClose("btnquery");
                eval("var ds=" + json.queryResult + ";");//将查询到的数据以json形式保存
                if (ds.ok != true) {
                    $("#message").empty();
                    $("#message").append(json.servertime + " 未查到任何记录,请修改查询条件后再查!");
                    return;
                }

                var tables = new Array();
                for (var key in ds) { //取出表名
                    if (key.indexOf("Table") >= 0)
                        tables.push(key);
                }
                for (var z = 0; z < tables.length; z++) {
                    var x = ds[tables[z]];
                    if (z > 0)
                        res.append("<hr/>");
                    res.append("<table id='t" + z + "' class='tableCss'></table>");
                    var strtem = "<tr><th style='text-align:center;'></th>";
                    for (var key in x[0]) { //返回列名
                        strtem += "<th style='text-align:center;'>" + key + "</th>";
                    }
                    strtem += "</tr>";
                    $("#t" + z).append(strtem);
                    for (var i = 0; i < x.length; i++) {
                        strtem = "<tr><td style='text-align:center;'>" + (i + 1) + ".</td>";
                        for (var key in x[0]) {
                            strtem += "<td style='text-align:center;'>" + x[i][key] + "</td>";
                        }
                        strtem += "</tr>";
                        $("#t" + z).append(strtem);
                    }
                    $("#message").empty();
                    $("#message").append(json.servertime + " 共查询到 " + ds[tables[0]].length + " 条记录!本次查询最大返回 " + maxreturnrows + " 条记录!");
                }
                loadingClose("btnquery");
            });

posted @ 2011-09-19 16:50  风一样的大叔  阅读(385)  评论(0编辑  收藏  举报