Skip to Content
avatar image
Former Member

Expression '{...}' instead of value...

Hello!

Again I ask to help to understand the problem ...

Please look at the code below:


<!DOCTYPE HTML>
<html>
  <head>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>
  <meta http-equiv="Cache-Control" content="no-cache">
  <title>DynamicTable</title>

  <script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
  id="sap-ui-bootstrap"
  data-sap-ui-libs="sap.m"
  data-sap-ui-theme="sap_bluecrystal"
  data-sap-ui-resourceroots='{"sap.ui.sample": "./"}'>
  </script>

  <script type="text/javascript">
  sap.ui.getCore().attachInit(function () {

  var model_structure = {
  output:{
       groups:[
            {group_id:"1", name:"Group-1"},
            {group_id:"2", name:"Group-2"}
       ],
      columns:[
            {id:"col1", name:"Column-1"},
            {id:"col2", name:"Column-2"}
       ],
       lines:[
            {col1:"1.1", col2:"1.2", group_id:"1"},
            {col1:"2.1", col2:"2.2", group_id:"1"},
            {col1:"3.1", col2:"3.2", group_id:"2"}
       ]
  }
 };

  var o_model = new sap.ui.model.json.JSONModel(model_structure);
  sap.ui.getCore().setModel(o_model, "data");

  var o_list_items;
  var o_table;

  o_list_items = new sap.m.ColumnListItem({
       cells: {
            path: "data>/output/columns",
            template: new sap.m.Text({
                 text: {
                      path: "data>id",
                      formatter: function(value){return '{data>'+value+'}';}
                 }
            })
       }
  });

  o_table = new sap.m.Table({
       columns: {
            path: 'data>/output/columns', 
            template: new sap.m.Column({
                 header: new sap.m.Text({text: "{data>name}"})
            })
       },
       items: {path: "data>/output/lines", template: o_list_items},
  });

  var app = new sap.m.App("App", {
       initialPage: "page1"
  });
  var page1 = new sap.m.Page("page_dynamic_table", {
       title : "DynamicTable",
       showNavButton : false,
       content : [ o_table ]
  });

  app.addPage(page1);
  app.placeAt("content");
  });
  </script>

  </head>
  <body class="sapUiBody" role="application">
  <div id="content"></div>
  </body>
</html>

When creating a table, I add aggregation 'items' (line 63). However, for some reason, are displayed in the table cell expression '{data> ...}'. In the place they need to put a value from the model.

Tell me, please, why is this happening? What am i doing wrong?

001.PNG (7.2 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Oct 26, 2015 at 07:27 AM

    try

    $.each(model_structure.output.columns, function(item, i) {

    var bindingInfo = { path : "data>" + i.id };

    o_list_items.addCell( new sap.m.Text( { text :  bindingInfo} ) );

    });

    instead

    JS Bin - Collaborative JavaScript Debugging

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hello, Maksim!

      Thank you for your help!

      I just tried to solve this problem without the use of structures, and take all the necessary data from the model. But if this is not possible, i will use your solution...

  • Oct 26, 2015 at 04:25 AM

    Hi Sergey

    it come from here

    formatter: function(value){return '{data>'+value+'}';} 

    Add comment
    10|10000 characters needed characters exceeded