EasyUI 常规用法

(function () {
    // 获取树的途径,如 社团分类 > YHBH > 河南省卫生厅 >
山东省株洲市
    var getBreadcrumbs = function (a) {
        var node2 = $(‘#tt’).tree(“getParent”, a.target);
        return !!node2 ? getBreadcrumbs(node2) + ” > ” + a.text :
a.text;
    };

    // 获取选中的树节点当前所处 Level
    var getNodeLevel = function (node) {
        var i = 1, parentNode;

        var getParent = function (node1) {
            parentNode = $(“#tt”).tree(“getParent”, node1.target);
            if (parentNode != null) {
                i++;
                getParent(parentNode);
            }
        };
        if (node == null) {
            return;
        }
        getParent(node);

        return i;
    };

    // 获取 DataGrid 的当选行们
    var getSelections = function () {
        return $(“#dg”).datagrid(“getSelections”);
    };

    window.Index = {
        getBreadcrumbs: getBreadcrumbs,
        getNodeLevel: getNodeLevel,
        getSelections: getSelections
    };

    var calcel = function () {
        $(“#win”).window(“close”);
    };

})();

 

/*
点击树的节点之后,获取数据,并填充 datagrid
在意,数据样例如下,
[{
    “OrgType”: 1,
    “OrgTypeValue”: null,
    “AuditProcess”:
“1,c93df86763504c2fa8226a6cf8ee9797,zhYHBJRole2|2,2e52574e7cf44c79b42bfa6f1d5b009c,zhYHBJRole1|3,9e3695dac51142ae8e7b3e963d924a32,zhYHBJRole6”,
    “AuditProcesses”: [{
        “ProcessId”: 1,
        “RoleId”: “c93df86763504c2fa8226a6cf8ee9797”,
        “RoleName”: “zhYHBJRole2”
    },
    “ReqCount”: 0,
    “ReqIndex”: 0
},

{
    “OrgType”: 2,
    “OrgTypeValue”: null,
    “AuditProcess”:
“1,2e52574e7cf44c79b42bfa6f1d5b009c,zhYHBJRole1|2,367c1816ea6946b4885755337378f8b3,zhYHBJRole3|3,cae20248433f419d8ad6ea43b7502403,zhYHBJRole5”,
    “AuditProcesses”: [{
        “ProcessId”: 1,
        “RoleId”: “2e52574e7cf44c79b42bfa6f1d5b009c”,
        “RoleName”: “zhYHBJRole1”
    },
    “ReqCount”: 0,
    “ReqIndex”: 0
}]
1:能够看看,该数额为多少为2的一个数组,存储为JSON
2:其后台代码为:
public JsonResult GetUserNotAuditOrg(string orgId)
{
    List<Organization> list =
_organizationBll.GetNotAuditChild(orgId, user);
    return Json(list, JsonRequestBehavior.AllowGet);
}
*/
var treeNodeClick = function (node) {
    var path = getBreadcrumbs(node);
    $(‘#routeTitle’).panel({
        title: ”  当前地方:社团分类 > ” + path
    });

    $.ajax({
        type: “POST”,
        url: “@ViewBag.Domain/Organization/GetUserNotAuditOrg?orgId=” +
node.id,
        success: function (data) {
            var orgProcessJson = [];
            // 遍历 JSON 数组
            $.each(data, function (i, item) {
                var currentProcess = item.CurrentAuditProcess;
                var processes = “”;
                // 借使某个元素的属性是数组,则能持续举行遍历处理
                $.each(item.AuditProcesses, function (j, jitem) {
                    if (currentProcess != null && currentProcess != “”
&& parseInt(currentProcess.split(“,”)[0]) ==
parseInt(jitem.ProcessId)) {
                        processes += “<span style=’color: red’>” +
jitem.RoleName + “</span>->”;
                    } else {
                        processes += “<span>” + jitem.RoleName +
“</span>->”;
                    }
                });
                item.AuditProcess = processes == “” ? “” :
processes.substring(0, processes.length – 2);
            });
            /* 直接加载 JSON 数组填充到 datagrid
               填充数据的其余一种做法,如下
                var rows = [];
                rows.push({ “name”: “系列类型属性名称:”, “value”:
levelName, “group”: item.Name });
                rows.push({ “name”: “种类类型属性值:”, “value”:
levelDefine, “group”: item.Name });
                rows.push({ “name”: “文本类型属性名称:”, “value”:
fieldName, “group”: item.Name });
                $(‘#properEditGrid’).propertygrid(‘loadData’, rows);
               注意 columns
也可那样来促成,那应当可以化解按钮授权的表格的列动态生成的难题。

            */
            $(‘#orgGrid’).datagrid(‘loadData’, data);
        }
    });
};

$(“#addtest”).bind(“click”, function () {
    var selected, isLeaf, level;

    selected = $(“#tt”).tree(‘getSelected’);
    if (selected == null) {
        $.messager.alert(“提醒”, “请选择题库分类!”, “info”);
        return;
    }

    level = Index.getNodeLevel(selected);

    if (level <= 3) {
        $(“#win”).window(“open”);
        $(“#win”).window(“refresh”, “/Home/QuestionCategoryAdd”);
    }
});

$(“#edittest”).bind(“click”, function () {
    var rows, rowsCount;
    rows = Index.getSelections();
    rowsCount = rows.length;
    if (rowsCount > 1) {
        $.messager.alert(“提醒”, “三遍只好编辑一条数据!”, “info”);
        return;
    }
    if (rowsCount == 0) {
        $.messager.alert(“提醒”, “请选用要编写的数量!”, “info”);
        return;
    }
    $(“#win”).window(“open”);
    $(“#win”).window(“refresh”, “/Home/QuestionCategoryAdd?categoryId=”

  • rows[0].Id + “&categoryName=” + rows[0].Name);
    });

$(“#removetest”).bind(“click”, function () {
    $.messager.confirm(“提示”, “您确定” + sourceNode.text + “要复制到” +
targetNode.text + “目录下啊?”, function (flag) {
        if (flag) {
        }
    });
});

$(“#savetest”).bind(“click”, function () {
    $.messager.prompt(“提醒”, “请输入名称.”);
});

此外,提供多少个常用的帮手方法:

function JsonToDate(value) {
    var data = value;
    var date = new Date(parseInt(data.replace(“/Date(“,
“”).replace(“)/”, “”), 10));
    var result = date.getFullYear() + “-” + (date.getMonth() + 1 < 10
? “0” + (date.getMonth() + 1) : date.getMonth() + 1) + “-” +
(date.getDate() < 10 ? “0” + date.getDate() : date.getDate()) + ” ” +
(date.getHours() < 10 ? “0” + date.getHours() : date.getHours()) +
“:” + (date.getMinutes() < 10 ? “0” + date.getMinutes() :
date.getMinutes()) + “:” + (date.getSeconds() < 10 ? “0” +
date.getSeconds() : date.getSeconds());
    return result;
}

function secondToTime(value) {
    return [parseInt(value / 60 / 60), parseInt(value / 60 % 60), value
% 60].join(“:”).replace(/\b(\d)\b/g, “0$1”);

}

function arrayToJson(o) {
    var r = [];
    if (typeof o == “string”) return “\”” +
o.replace(/([\’\”\\])/g, “\\$1”).replace(/(\n)/g,
“\\n”).replace(/(\r)/g, “\\r”).replace(/(\t)/g, “\\t”) +
“\””;
    if (typeof o == “object”) {
        if (!o.sort) {
            for (var i in o)
                r.push(i + “:” + arrayToJson(o[i]));
            if (!!document.all &&
!/^\n?function\s*toString\(\)\s*\{\n?\s*\[native
code\]\n?\s*\}\n?\s*$/.test(o.toString)) {
                r.push(“toString:” + o.toString.toString());
            }
            r = “{” + r.join() + “}”;
        } else {
            for (var i = 0; i < o.length; i++) {
                r.push(arrayToJson(o[i]));
            }
            r = “[” + r.join() + “]”;
        }
        return r;
    }
    return o.toString();
}