我正在尝试使用ajax数据源加载kendo树视图。这是我的HTML
<div ng-controller="TreeController" style="margin-left:200px;">
<div kendo-tree-view k-options="treeOptions"
k-data-source="treeObj" id="ktree"></div>
<br />
</div>
这是我的javascript
.success(function (datax) {
//if (data.length == 0) {
// //customerGroupParentNodeCode="NewTree"
// $scope.customerGroupParentNode = "NewTree";
//}
arr = [];
for (var i = 0; i < datax.length; i++) {
arr.push({
id: datax[i].Child_Code,
text: datax[i].Child_Name,
parent: datax[i].Parent_Code
});
}
var startingPoint = loggedLocation + '/ROOT-0';
arr2 = getNestedChildren(arr, startingPoint);
alert(getNestedChildren(arr, startingPoint)[0].items[0].id)
var knobj2 = new kendo.data.HierarchicalDataSource({
data: arrayObj
});
//setting heirarchial data to scope
$scope.treeObj = knobj2;
}).error(function (data) {
});
但是树没有加载ajax成功。当我从ajax请求声明数组与生成的数组完全相同时,生成了kendo树。
var arrayObj = [{
id: 2,
text: "test",
expanded: true,
items: [{
id: 10,
text: "February.pdf",
//spriteCssClass: "pdf"
}, {
id: 11,
text: "March.pdf",
//spriteCssClass: "pdf"
}, {
id: 12,
text: "April.pdf",
//spriteCssClass: "pdf"
}]
}]
var knobj = new kendo.data.HierarchicalDataSource({
data: arr2
});
//setting heirarchial data to scope
$scope.treeObj = knobj;
这是有效的。
答案 0 :(得分:0)
你可以在成功功能中添加:
var treeview = $("#treeview").data("kendoTreeView");
treeview.setDataSource(data);
make setDataSource(dataArray)
初始化treeView