0

我的 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; }
}

有什么明显错误或调试这类事情的任何提示吗?

4

1 回答 1

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"]}]

于 2013-04-08T10:52:56.840 回答