Kendo UI KendoTreeView HierarchicalDataSource不显示节点

时间:2013-04-05 16:01:45

标签: javascript html model-view-controller kendo-ui

我的Kendo UI TreeView没有将返回的JSON对象添加到树视图中。

我可以从调用的控制器方法看到,给予DataSource的Json看起来像这样(但是有更多的文件和文件夹)

{"NodeID":-842352767, "Name":"/", "Folders":[{"NodeID":1804712307,"Name":"/$Recycle.Bin","Folders":null,"Files":null},{"NodeID":-582712839,"Name":"/Windows","Folders":null,"Files":null}], "Files":["/.rnd","/msdia80.dll"]}

我的观点如下:

@model ProjName.Models.BrowseNode

<div id ="wrapper">
<h1>Browser</h1>
<div id="treeview" style="float:left;margin: 40px;">
</div>
</div>
<script>
function populateTreeView() {
    var remoteDataSource = new kendo.data.HierarchicalDataSource({
        type: "json",
        transport: {
            read: "FileBrowser/GetHierarchy"
        },
        schema: {
            model: {
                id: "NodeID",
                text: "Name",
                expanded: false,
                children: "Folders",
            },
        }
    });

    $("#treeview").kendoTreeView({
        dataSource: remoteDataSource,
        dataTextField: "Name"
    });
}

$(document).ready(function () {
    populateTreeView();
});

将BrowseNode定义为:

public class BrowseNode
{
    public int NodeID { 
        get
        {
            if (null == Name)
                return default(int);
            return Name.GetHashCode();   
        }
    }
    public string Name { get; set; }
    public List<BrowseNode> Folders { get; set; }
    public List<string> Files { get; set; }
}

任何明显错误或有任何调试此类事情的提示?

1 个答案:

答案 0 :(得分:1)

事实证明我的JSON不是DataSource想要的。它应该是在顶层返回的数组,因此JSON被[]括号包围如下:

[{"NodeID":-842352767, "Name":"/", "Folders":[{"NodeID":1804712307,"Name":"/$Recycle.Bin","Folders":null,"Files":null},{"NodeID":-582712839,"Name":"/Windows","Folders":null,"Files":null}], "Files":["/.rnd","/msdia80.dll"]}]