Skip to Content
author's profile photo Former Member
Former Member

How to access Modeldata in my View (build treenodes)

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Aug 22, 2012 at 06:36 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.