1
我想通過Kendo TreeView顯示文件夾結構...如果我在視圖中插入項目,它工作正常。當我嘗試使用遠程數據綁定進行操作時,它只顯示父節點,並且沒有選項可供展開...即使該文件夾內有其他文件夾/文件。這裏是代碼:Kendo TreeView與遠程數據綁定不顯示兒童
Html.Kendo().TreeView()
.Name("DownloadTreeView")
.DataTextField("Name")
.DataSource(dataSource => dataSource
.Read(read => read.Action("GetFiles", "DownloadSettings"))
)
.ExpandAll(true)
.Render();
public JsonResult GetFiles(string path)
{
const string StartDirectory = @"L:\dsms\assets";
path = path ?? StartDirectory;
var files = Directory.GetFiles(path).Select(file =>
new DownloadTreeViewVM
{
Id = file,
HasChildren = false,
Name = Path.GetFileName(file)
});
var directories = Directory.GetDirectories(path).Select(dir =>
new DownloadTreeViewVM
{
Id = dir,
HasChildren = Directory.GetFiles(dir).Any() || Directory.GetDirectories(dir).Any(),
Name = Path.GetFileName(dir)
});
var result = files.ToList();
result.AddRange(directories);
result = result.OrderBy(x => !x.HasChildren).ToList();
return Json(result, JsonRequestBehavior.AllowGet);
}
任何想法?
預先感謝您。
謝謝你的答案刪除ExpandAll(真)。其實我做到了這一點:hasChildren,而不是「HasChildren」...現在它工作... –