Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all!

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'):

JavaScript
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:

JavaScript
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 OKay and I can see children in that way. But by default, property of 'hasChildren' is 'true' and I make scheme for children like in API reference:

JavaScript
children: { // <- instead of "PhoneCalls"
  schema: {
    data: "PhoneCalls",
      model: {
        hasChildren: false
        }
     }
  }


, and quite lose children.

Can anyone help define children property with scheme correctly?
Posted

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900