cancel
Showing results for 
Search instead for 
Did you mean: 

How to access Modeldata in my View (build treenodes)

Former Member
0 Kudos

Hello together

Don't know how to build up a tree-control from xmlmodel data, held by controller.

Therefore i´ve tried to access the values from my model in view, but can't get the values.

In my controller in 'onInit:' function i have set the model to the treecontrol 

CONTROLLER:

this.byId("firstTree").setModel(xmlmodel);

Next, in my view file i tried to build the treenodes by looping over modeldata and a them to the tree.

That failed. I can set the values for the subnodes and after the rendering i see the right values in my browser.

Don't know if this is the best way. I'm grateful for any help.

Static loops with fixed counts:

MYVIEW:

var tree = new sap.ui.commons.Tree(this.createId("firstTree"),{

                          title: "{pathOfHeadervalue}",

                          showHeaderIcons : true,

                          showHeader: true,

                         

                });

                var index = 0;               

                for (var i = 0; i < 5; i++)

                      {

                          var node = new sap.ui.commons.TreeNode(this.createId("node_")+i);

                          node.setText(this.createId("node_")+i);

                          for(var j = 0; j < 3; j++)

                                {

                                    subnode = new sap.ui.commons.TreeNode(this.createId("node_") + i + "_" + j, {

                                              text: "{pathOfHeaderValue/"+ (index++) + "/Value}",

                                              expanded: false

                                    });    

                                     alert(subnode.getText());     //this is empty !!!

                                    node.addNode(subnode);

                                }

                          tree.addNode(node);                         

                      }   

  many thanks for an answer

chris

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

by exploring the api an much trial and error , i get a flat tree structure of an existing xmlmodel. in this case {path} is from the model binding to the element 'firstTree' in controller. But how can i define the tree more dynamically and with deeper structure ?

// Treenode used for every entry in the model

                var nodeTemplate = new sap.ui.commons.TreeNode({

                          text: "{Path/text()}",

                          expanded: false

                })

// tree with aggregation nodes;

                var ltree = new sap.ui.commons.Tree(this.createId("firstTree"),{

                          title: "{path}",

                          showHeaderIcons : true,

                          showHeader: true,

                          nodes: {path: "/", template: nodeTemplate}

                         

                }); 

Kind regards

Chris