我的Kendo UI TreeView沒有獲取添加到樹視圖的返回JSON對象。Kendo UI KendoTreeView HierarchicalDataSource未顯示節點
我可以從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; }
}
任何明顯錯誤或任何提示調試這種事情?
你如何改變你的JSON,能否請您詳細些嗎? – 2013-07-21 06:04:30
我的孩子(你的文件夾)顯示爲undefined! – 2013-07-21 06:04:59
聽起來像一個不同的問題。我必須改變的是從json對象到它預期的json數組。也就是從'{'parent':1}'到'[{'parent':1}]' – James 2013-07-21 13:28:50