Regarding to a API reference for Kendo (proof: Kendo UI API Reference - Schema.Model.Children), children nodes can be declare in next approach (see nested 'schema' as 'define options for second level'):
var datasource = new kendo.data.HierarchicalDataSource({
data: [
{
categoryName: "SciFi",
movies: [
{ title: "Star Wars: A New Hope", year: 1977, cast: [
{ actor: "Mark Hamill", character: "Luke Skywalker" },
{ actor: "Harrison Ford", character: "Han Solo" },
{ actor: "Carrie Fisher", character: "Princess Leia Organa" }
] },
{ title: "Star Wars: The Empire Strikes Back", year: 1980, cast: [
{ actor: "Mark Hamill", character: "Luke Skywalker" },
{ actor: "Harrison Ford", character: "Han Solo" },
{ actor: "Carrie Fisher", character: "Princess Leia Organa" },
{ actor: "Billy Dee Williams", character: "Lando Calrissian" }
] }
]
}
],
schema: {
model: {
children: { // define options for second level
schema: {
data: "movies",
model: {
children: "cast" // third level is defined by the field "cast"
}
}
}
}
}
});
I use similar definition for HierarchicalDataSource and get children nodes in that way:
schema: {
model: {
id: "urb_fltr",
hasChildren: true,
children: "PhoneCalls" // <- here is definition for children that are - data from field of output (next in parse)
},
parse: function (data) {
var outRes = [];
var dataRes = [];
var tmpLoop = 0;
var bordNum = 251170009;
if (data.d.results != null && data.d.results.length > 0)
for (var step = 0; step < data.d.results.length; step++) {
if (data.d.results[step] == null) continue;
var stepData = data.d.results[step];
var stepValue = (stepData.urb_subject != null) ? stepData.urb_subject.Value : 0;
var arrValue = (stepValue > bordNum) ? stepValue - bordNum : 0;
if (outRes[arrValue] == null || typeof (outRes[arrValue]) == 'undefined') {
outRes[arrValue] = {};
outRes[arrValue].urb_total = 1;
outRes[arrValue].urb_clnts = 0;
outRes[arrValue].OwnerId = stepData.OwnerId;
outRes[arrValue].urb_subjectValue = stepValue;
outRes[arrValue].PhoneCalls = []; // <- children
}
else
outRes[arrValue].urb_total += 1;
// fill children field
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1] = {};
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1].CallId = stepData.ActivityId;
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1].urb_name = stepData.urb_name;
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1].CreatedOn = stepData.CreatedOn;
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1].PhoneNumber = stepData.PhoneNumber;
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1].ScheduledEnd = stepData.ScheduledEnd;
if (stepData.RegardingObjectId != null && stepData.RegardingObjectId.Id != null && stepData.RegardingObjectId.LogicalName == "lead") {
outRes[arrValue].PhoneCalls[outRes[arrValue].urb_total - 1].RegardingObjectId = stepData.RegardingObjectId;
outRes[arrValue].urb_clnts += 1;
}
}
for (var loop = 0; loop < outRes.length; loop++)
if (typeof (outRes[loop]) != 'undefined') {
outRes[loop].urb_subjectName = outRes[loop].urb_subjectName + " ( " + outRes[loop].urb_total + " - " + outRes[loop].urb_clnts + " )";
dataRes[tmpLoop] = outRes[loop];
tmpLoop++;
}
return dataRes; //data.d.results;
},
type: "json"
}
It's OK. I can see children in that way. But by default, property of 'hasChildren' is 'true' and I add scheme for children nodes like in API reference:
children: { // <- instead of "PhoneCalls" - next 'schema'
schema: {
data: "PhoneCalls",
model: { hasChildren: false }
}
}
, and quite lose children.
Can anyone help define children property with scheme correctly?
Solution: 1. Forget about 'schema' brace in 'children' - turn back the "PhoneCalls" string value. 2. Add the 'hasChildren' property in the 'PhoneCall' object (from "PhoneCalls" set) and set the value in 'false'.
If you want to add new level of treeview: 1. Set the 'hasChildren' property of "PhoneCall" objects in 'true' 2. Add the subordinated set as attribute of "PhoneCall" objects 3. Add the 'children' property in "PhoneCall" objects that would be a string value - name of set attribute from p. 2