zoukankan      html  css  js  c++  java
  • 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();
        }
  • 相关阅读:
    java实现获取当前年月日 小时 分钟 秒 毫秒
    四种常见的 POST 提交数据方式(application/x-www-form-urlencoded,multipart/form-data,application/json,text/xml)
    Cannot send, channel has already failed:
    Java 枚举(enum) 详解7种常见的用法
    C语言指针详解(经典,非常详细)
    ActiveMQ进阶配置
    Frame size of 257 MB larger than max allowed 100 MB
    SpringJMS解析--监听器
    SpringJMS解析-JmsTemplate
    delphi 修改代码补全的快捷键(由Ctrl+Space 改为 Ctrl + alt + Space)
  • 原文地址:https://www.cnblogs.com/wjx-blog/p/14523842.html
Copyright © 2011-2022 走看看