KendoTreeView复选框全部清除

时间:2015-05-06 07:59:43

标签: jquery kendo-treeview

我正在使用KendoTreeView控件来分层数据。此外,我需要提供ClearAll功能,其中表格中的所有其他字段,包括在KendoTreeView中进行的选择应该被清除。所以我写了这样的东西:

 public ClearAll(): void {
        $('#myTreeView').find('input:checkbox').each(function (index,element) {
            $(element).prop('checked', false);
        });
            }

虽然这会从树视图中清除所有选中的复选框,但是在此之后如果我再次检查父节点 - 则不会检查子复选框。

此行为(子节点未被检查)仅在第一次发生,因此如果我取消选中并再次检查父节点 - 将检查子节点。

我为此问题模拟了示例:

http://dojo.telerik.com/@rahul_ec27/ALihu

2 个答案:

答案 0 :(得分:0)

再次设置DataSource将重置检查,

     function ClearAll(){

      $("#treeview").data("kendoTreeView").setDataSource([
                {
                    id: 2, text: "Kendo UI Project", expanded: true, spriteCssClass: "folder", items: [
                        { id: 3, text: "about.html", spriteCssClass: "html" },
                        { id: 4, text: "index.html", spriteCssClass: "html" },
                        { id: 5, text: "logo.png", spriteCssClass: "image" }
                    ]
                },
                {
                    id: 6, text: "New Web Site", expanded: true, spriteCssClass: "folder", items: [
                        { id: 7, text: "mockup.jpg", spriteCssClass: "image" },
                        { id: 8, text: "Research.pdf", spriteCssClass: "pdf" },
                    ]
                },
                {
                    id: 9, text: "Reports", expanded: true, spriteCssClass: "folder", items: [
                        { id: 10, text: "February.pdf", spriteCssClass: "pdf" },
                        { id: 11, text: "March.pdf", spriteCssClass: "pdf" },
                        { id: 12, text: "April.pdf", spriteCssClass: "pdf" }
                    ]
                }
            ]);
  }

答案 1 :(得分:0)

HTML

public void UpsertSharepointFiles()
        {
            try
            {



  var spList = GetSharepointDirectories();

            var targetDir = @"\\111.111.0.11\c$\websites\XXX\FormLibrary";

            IntPtr token = IntPtr.Zero;
            bool valid = LogonUser("administrator",
                        "XXX",
                        "XXX",
                        (int)LogonType.NewCredentials,
                        (int)LogonProvider.WinNT50,
                        ref token);

            if (valid)
            {

                using (WindowsImpersonationContext context = WindowsIdentity.Impersonate(token))
                {

                    CloseHandle(token);

                    //var targetDir = Server.MapPath("~/TempCopy");
                    //var targetDir = @"\\\\222.222.2.22\c$\websites\XXX\FormLibrary";
                    var targetDirInfo = new DirectoryInfo(targetDir);

                    var dirs = targetDirInfo.GetDirectories("*.*", SearchOption.AllDirectories);

                    if (spList != null)
                    {

                        foreach (var spFile in spList)
                        {
                            if (spFile.Content != null)
                            {
                                foreach (var dir in dirs)
                                {
                                    var searchFile = dir.GetFiles(spFile.LeafName);
                                    var currDirName = dir.Name;

                                    if (currDirName == "ABBH")
                                    {
                                        currDirName = "ABB";
                                    }

                                    if (searchFile.Count() == 0) //Web Server - No, SP - Yes
                                    {
                                        CreateFileOnWebServer(currDirName, spFile, targetDir);
                                    }
                                    else // Web Server - Yes, SP - Yes
                                    {
                                        UpdateFileOnWebServer(searchFile, spFile, targetDir, currDirName);
                                    }
                                }

                            }
                        }

                        foreach (var dir in dirs)
                        {
                            DeleteFilesOnWebServerNotInSharepointDb(dir, spList);
                        }
                    }
                }

                lblSuccessMessage.Text = "Forms Library in Website successfully synced with Sharepoint Forms Library!";
                lblSuccessMessage.Visible = true;
            }
        }
        catch (Exception)
        {
            lblErrorMessage.Text = "Error occurred when syncing Forms Library in Website.  Please try again.";
            lblErrorMessage.Visible = true;
        }

    }

private static void DeleteFilesOnWebServerNotInSharepointDb(DirectoryInfo dir, List<SharepointVO> spList)
        {
            var dirFileList = dir.GetFiles();

            var filesOnServerNotInSharepointDb = dirFileList.Where(w => spList.All(s => s.LeafName != w.Name));
            foreach (var file in filesOnServerNotInSharepointDb)
            {
                var fInfo = new FileInfo(file.DirectoryName + @"\" + file.Name).ToString();
                System.IO.File.Delete(fInfo);
            }
        }

        private static void UpdateFileOnWebServer(FileInfo[] searchFile, SharepointVO spFile, string targetDir,
            string currDirName)
        {
            if (searchFile[0].Directory.Name == spFile.Directory)
            {
                // Replace file with Sharepoint file
                if (spFile.ContentLength != searchFile[0].Length) //Checks only first file
                {
                    WriteFile(currDirName, spFile, targetDir);
                }
            }
        }

        private static void CreateFileOnWebServer(string currDirName, SharepointVO spFile, string targetDir)
        {
            if (currDirName == spFile.Directory)
            {
                // Check if directory exists on server
                if (Directory.Exists(targetDir + "/" + currDirName))
                {
                    {
                        {
                            WriteFile(currDirName, spFile, targetDir);
                        }
                    }
                }
                else
                {
                    Directory.CreateDirectory(targetDir + "/" + currDirName);

                    WriteFile(currDirName, spFile, targetDir);
                }
            }
        }

        private static void WriteFile(string currDirName, SharepointVO spFile, string targetDir)
        {
            using (
                Stream fs =
                    System.IO.File.OpenWrite(targetDir + "/" + currDirName + "/" + spFile.LeafName))
            {
                fs.Write(spFile.Content, 0, spFile.Content.Length);
            }
        }

        [DllImport("advapi32.dll", SetLastError = true)]
        public static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);

        [DllImport("kernel32.dll")]
        public static extern bool CloseHandle(IntPtr token);

        enum LogonType
        {
            Interactive = 2,
            Network = 3,
            Batch = 4,
            Service = 5,
            Unlock = 7,
            NetworkClearText = 8,
            NewCredentials = 9
        }

        enum LogonProvider
        {
            Default = 0,
            WinNT35 = 1,
            WinNT40 = 2,
            WinNT50 = 3
        }

的JavaScript

<button id="btnclear" class="k-button" onclick="ClearAll();">Clear All</button>