• treelist使用url地址做为数据源时,实现全部展开与全部折叠的方法之一


    从网上找的方法,备注:这个方法不好使

    var treelist =   $("#treelist").data('kendoTreeList');
    treelist.options.dataSource.schema.model.expanded = !treelist.options.dataSource.schema.model.expanded
    treelist.setDataSource( treelist.options.dataSource)

    自己实现的方法:

    新建一个数据源的函数,然后把是否展开传过去,如下:

    function getDataSource(isExpland) {
            var dataSource = new kendo.data.TreeListDataSource({
                transport: {
                    read: {
                        url: "@Html.UrlHref("LocalSite", "/BaseInfoManagement/CaseManagement/AllCaseFolder")" + "?CaseId=" + $.getUrlParam('CaseId')
                    },
                    update: {
                        url: "@Html.UrlHref("LocalSite", "/BaseInfoManagement/CaseManagement/UpdateCaseFolder")",
                        dataType: "json",
                        type: "POST"
                    },
                    destroy: {
                        url: "@Html.UrlHref("LocalSite", "/BaseInfoManagement/CaseManagement/DestroyCaseFolder")"
                    },
                    create: {
                        url: "@Html.UrlHref("LocalSite", "/BaseInfoManagement/CaseManagement/CreateCaseFolder")" + "?CaseId=" + $.getUrlParam('CaseId'),
                        dataType: "json",
                        type: "POST"
                    },
    
                    parameterMap: function (options, operation) {
                        if (operation !== "read" && options.models) {
                            return { models: kendo.stringify(options.models) };
                        }
                    }
                },
                requestStart: function (e) {
                    parent.ShowLoading();
                },
                requestEnd: function (e) {
                    parent.HiddeLoading();
                    var response = e.response;
                    var type = e.type;
                    if (type == "update" || type == "create") {
                        if (response && response.id) {
                            ShowNotify("目录" + (type == "create" ? "添加" : "修改") + "成功!");
                        }
                    }
    
                },
                batch: true,
                schema: {
                    model: {
                        id: "ID",
                        fields: {
                            parentId: { field: "PARENT_ID", nullable: true },
                            NAME: { type: "string", editable: true, nullable: false, validation: { required: true } },
                            CASE_FOLDER_KIDE_DISPLAY: { type: "string", nullable: true, validation: { required: false } },
                            CASE_FOLDER_KIDE: { type: "string", editable: true, nullable: true, validation: { required: false } },
                            IS_EMAIL_FOLDER_DISPLAY: { type: "string", nullable: true, validation: { required: false } },
                            IS_EMAIL_FOLDER: { type: "string", editable: true, nullable: true, validation: { required: false } },
    
                            CASE_FOLDER_KIDEDropdownlistValue: { defaultValue: { ParaValue: 0, DisplayCode: "[文件夹类]" } },
                            IS_EMAIL_FOLDERDropdownlistValue: { defaultValue: { ParaValue: 0, DisplayCode: "" } }
                        },
                        expanded: isExpland
                    },
                    data: function (response) {
                        if (response.Data && response.Data.error) {
                            ShowNotify(response.Data.msg, true);
                            return response.Data.model;
                        }
                        return response;
                    }
                }
            });
            return dataSource;
        }

    初始化时,默认展开:

    $(document).ready(function () {
            $("#treelist").kendoTreeList({
                dataSource: getDataSource(true),
                toolbar: [{ name: "create", text: "添加根信息", class: "sss" }, { name: "unExpandAll", text: "全部折叠", click: unExpandAll }, { name: "expandAll", text: "全部展开", click: expandAll }],
                save: function (e) {
                    //ShowLoading();
                },
                dataBound: function (e) {
                    //HiddeLoading();
                },
                //height: 540,
                columns: [
                    {
                        field: "NAME", expandable: true, title: "名称"
                    },
                    {
                        field: "CASE_FOLDER_KIDE", title: "类型", editor: CASE_FOLDER_KIDE_Editor,  template: "#:CASE_FOLDER_KIDE_DISPLAY#",  155, headerAttributes: { style: "text-align: center;" }, attributes: { style: "text-align: center;" }
                    },
                    {
                        field: "IS_EMAIL_FOLDER", title: "包含", editor: IS_EMAIL_FOLDER_Editor,  template: "#:IS_EMAIL_FOLDER_DISPLAY#", 85, headerAttributes: { style: "text-align: center;" }, attributes: { style: "text-align: center;" }
                    },
                    {
                        field: "", title: " ",  45, template: $("#templateToTop").html(), headerAttributes: { style: "text-align: center;" }, attributes: { style: "text-align: center;" }
                    },
                    {
                        field: "", title: " ",  35, template: $("#templateToUp").html(), headerAttributes: { style: "text-align: center;" }, attributes: { style: "text-align: center;" }
                    },
                    {
                        field: "", title: " ",  35, template: $("#templateToDown").html(), headerAttributes: { style: "text-align: center;" }, attributes: { style: "text-align: center;" }
                    },
                    {
                        field: "", title: " ",  115, template: $("#templateFromTemplate").html(), headerAttributes: { style: "text-align: center;" }, attributes: { style: "text-align: center;" }
                    },
                    {
                        command: [{ name: "createChild", text: "添加子目录", attributes: { title: "添加子目录" } }, { name: "edit", text: "编辑" }, { name: "delete", text: "删除", click: FnDelete }],  225
                    }
                ],
                editable: true
            });
        });

    用按钮控件:

        function expandAll() {
            var treelist = $("#treelist").data('kendoTreeList');
            treelist.setDataSource(getDataSource(true));
            treelist.dataSource.read();
        }
        function unExpandAll() {
            var treelist = $("#treelist").data('kendoTreeList');
            treelist.setDataSource(getDataSource(false));
            treelist.dataSource.read();
        }
  • 相关阅读:
    AcWing 37. 树的子结构
    AcWing 30. 正则表达式匹配 (剑指OFFER leetcode 10)
    Leetcode 514 自由之路
    AcWing 28. 在O(1)时间删除链表结点
    solrCloud+tomcat+zookeeper配置
    ZooKeeper原理及配置
    ZooKeeper原理及配置
    ZooKeeper原理及配置
    SolrCloud Hello Word
    SolrCloud Hello Word
  • 原文地址:https://www.cnblogs.com/wjx-blog/p/14523842.html
Copyright © 2020-2023  润新知