This is a migrated thread and some comments may be shown as answers.

Null on DataTextField for TreeView

5 Answers 298 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
axwack
Top achievements
Rank 1
axwack asked on 03 Feb 2016, 09:19 PM

I need a bit of guidance on Treeview. My hierarchical datasource makes an ajax call to a webservice that returns a NULL on he first node of the tree. There is a reason for this because the Parent is the node represents the name of the actual Tree. Each subsequent node is the actual tree nodes. Also the JSON object returned is a nested, Complex object.

 Here is an example: 

{"id": 1, "isSSMNameNode": true, "tgtWeight": 0.0, "currWeight": 0.0, "hasChildNode": true, "ext_model_id": 1, "parent": null, "SSM": {"id": 1, "securitySelectionModelName": "vincent", "userCreatedModel": "[{\"classificationName\":\"vincent\",\"id\":1,\"expanded\":true,\"hasChildNode\":true,\"child\":[{\"classificationName\":\"MBS\",\"id\":14,\"expanded\":true,\"hasChildNode\":true,\"child\":[{\"classificationName\":\"Money Market\",\"id\":17,\"hasChildNode\":false}]}]}]", "classificationNames": []}, "classificationNameNode": null}

 

I've tried to use Schema.parse to make the nodes into a flat object but for some reason I lose the tree hierarchy when I try to do: 

 

var node = {
..
hasChildren = response.hasChildNode;
..
}
 

For some reason the hasChildren disappears from the node object  so that didn't work for me. Any ideas on how to get the first node to produce some value from the object and then have the name from the subsequent JSON object return?

 

What w 

 

 

5 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 08 Feb 2016, 09:00 AM

Hello axwack,

The code

var node = {
..
hasChildren = response.hasChildNode;
..
}

does not appear to be valid JavaScript. If this is JSON, it should be

var node = {
   hasChildren: response.hasChildNode
}

If this does not help to resolve the problem, please provide a sample that shows the problem -- in particular, what the expected result is, based on the provided data.

Regards,
Alex Gyoshev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
axwack
Top achievements
Rank 1
answered on 08 Feb 2016, 11:45 AM

 

The expected outcome is that the Node object would have hasChildren populated. When it gets to Parse, this attribute is omitted and the Treeview Node doesn't have the styling that allows you to see what the children are. 

var securitySelectionModelData = new kendo.data.HierarchicalDataSource({
       transport: {
            read: {
                url:  "../../getSavedClassificationModel/{{ id }}",
                contentType: "application/json",
                datatype: "json",
            }
       },
       schema: {
           type: "json",
           model: {
               id: "id",
               hasChildren: "hasChildNode"
           },
           parse: "",
            data: function(data){
 
                if (data.length > 0){
                    return data;
                } else {
                    return [data];
                }
            }
           parse: function(response) {
                      var nodes = [];
 
                      if(response.parent == null){
                          var node = {
                            id: response.id,
                            currWeight: response.currWeight,
                            tgtWeight: response.tgtWeight,
                            parentId: response.parent,
                            hasChildren: response.hasChildNode,
                            SSM_id: response.SSM.id,
                            ext_model_id: response.ext_model_id,
                            securitySelectionModelName: response.SSM.securitySelectionModelName,
                            classificationNameNode: response.classificationNameNode
                        };
                      }
                      else {
                          var node = {
                            id: response.id,
                            currWeight: response.currWeight,
                            tgtWeight: response.tgtWeight,
                            hasChildren: response.hasChildNode,
                            parentId: response.parent.id,
                            SSM_id: response.SSM.id,
                            ext_model_id: response.ext_model_id,
                            securitySelectionModelName: response.SSM.securitySelectionModelName,
                            classificationNameNode: response.classificationNameNode.classificationName
                        };
                      }
 
                        nodes.push(node);
 
                      return nodes;
                    }
       }
    });
0
Alex Gyoshev
Telerik team
answered on 10 Feb 2016, 11:41 AM

Hello axwack,

The schema.parse method will be executed prior to the nodes being created, and the method will make the conversion from hasChildNode to hasChildren. Then, the node will look for the hasChildNode field, and will not find it. To resolve this, set model.hasChildren = "hasChildren". See this Dojo snippet for a working demo.

Regards,
Alex Gyoshev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
axwack
Top achievements
Rank 1
answered on 10 Feb 2016, 12:43 PM

Thank you for your response. The funny thing is, the hasChildren attribute doesn't get populated even though it is explicitly set in the Javascript object. Take a look at the following screenshot from Kendo UI. Notice that the node is not even in the datasource.

On the PARSE function, it populates but kendo doesn't have this in its array. 

 Is this a bug?

0
Alex Gyoshev
Telerik team
answered on 12 Feb 2016, 10:52 AM

Hello axwack,

The output from the parse function appears to be valid. Is the schema.model definition hasChildren: "hasChildren", as previously suggested? If it is, and the problem persists, please adjust the Dojo snippet from my previous post so that it shows the problem.

Regards,
Alex Gyoshev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
TreeView
Asked by
axwack
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
axwack
Top achievements
Rank 1
Share this question
or