cancel
Showing results for 
Search instead for 
Did you mean: 

Problem mit Binding

Former Member
0 Kudos

Hello All,

I have some problem with Binding - Can someone help ?

Table is displayed without data.

Thanks in Advance,

Amyn

Code of Index.html :

<!DOCTYPE html>   
<html>   
<head>   
<!-- Added charset='utf-8' to handle data in various langauges -->   
<meta http-equiv='X-UA-Compatible' content='IE=edge' charset='utf-8' />   
<title>Stock</title>   
<!-- Load UI5, select gold reflection theme and the "commons" and "table" control libraries -->   
<script id='sap-ui-bootstrap' type='text/javascript'   
          src='resources/sap-ui-core.js' data-sap-ui-theme='sap_platinum'   
          data-sap-ui-libs='sap.ui.commons,sap.ui.table'></script>   
                                   <script type="text/javascript"> 
         //Create an instance of the table control
           var oTable = new sap.ui.table.Table({ title : "Artikel" });   
         //Define the columns and the control templates to be used
           oTable.addColumn(new sap.ui.table.Column({   
               label : new sap.ui.commons.Label({ text : "Material" }),   
//              template : new sap.ui.commons.TextView().bindProperty("Matnr", "Matnr"),
                template: new sap.ui.commons.TextView({text:"{Material}"}),
                 width : "50px" }));  
                              
               var oModel = new sap.ui.model.json.JSONModel(); 

 

             
               var url = 'http://abc.com:8026/sap/opu/odata/SAP/Z_AM_TEST_SRV/MaterialSet';  
                        $.ajax({  
                                 url : url,   
                                 jsonpCallback : 'getJSON',   
                                 contentType : "application/json",   
                                 dataType : 'jsonp', 
                                 success : function(data) {   
                                
                   oModel.setData(data);   
                   sap.ui.getCore().setModel(oModel);   
                   //Create a model and bind the table rows to this model
                   var oModel1 = new sap.ui.model.json.JSONModel();   
                   //Get the material array table from MaterialSet object
                   var aData = oModel.getProperty("d/MaterialSet");   
//                  oModel1.setData({ modelData : aData });   
                   oModel1.setData({ modelData : [ {"Material": ""}] });    
                   oTable.setModel(oModel1);
                                             }   
                      });   
                      
      oTable.bindRows("/modelData");   
      oTable.placeAt('content');   
// https://scn.sap.com/thread/3401770              
            </script>   
</head>   
    <body class='sapUiBody'>   
       <div id='content'></div>   
   </body>   
      
   </html> 

Accepted Solutions (1)

Accepted Solutions (1)

Joseph_BERTHE
Active Contributor
0 Kudos

<!DOCTYPE html>

<html>

<head>

  <meta http-equiv="X-UA-Compatible" content="IE=edge"/>

  <meta charset="UTF-8">

  <title>Hello World App</title>

  <script src="https://sapui5.netweaver.ondemand.com/resources/sap-ui-core.js" type="text/javascript"

  id="sap-ui-bootstrap"

  data-sap-ui-theme="sap_bluecrystal"

  data-sap-ui-libs="sap.ui.commons,sap.ui.table">

  </script>

    <script type="text/javascript">

  var oTable = new sap.ui.table.Table({ title : "Artikel" }); 

       

        oTable.addColumn(new sap.ui.table.Column({  

              label : new sap.ui.commons.Label({ text : "Material" }),  

                template: new sap.ui.commons.TextView({text:"{matnr}"}),

                width : "50px" })); 

        var oModel = new sap.ui.model.json.JSONModel({

         d : [ { matnr : "Test" } ]

        }); 

       

        oTable.setModel(oModel);

        oTable.bindRows("/d/");  

        oTable.placeAt('content');  

       

  </script>

</head>

<body class="sapUiBody" id="content">

</body>

</html>

If you take this example you will be able to solve your problem. Take care about the binding path and which model you set

Regards

Former Member
0 Kudos

Thanks for your help !

Answers (3)

Answers (3)

former_member182372
Active Contributor
0 Kudos

WHY do use jsonmodel to laod odata?????

Former Member
0 Kudos

Hello !

can you please give me a proposal !

Thanks and regards,

Amyn

former_member182372
Active Contributor
0 Kudos

Odatamodel

Private_Member_15166
Active Contributor
0 Kudos

Can you post error in browser's console?

Joseph_BERTHE
Active Contributor
0 Kudos

Hello,

Could you please provide us the JSON output file.

Generally with JSon the result set is something like : "/d/results/" whereas you use :

var aData = oModel.getProperty("d/MaterialSet"); 

Maybe this is the issue.

Regards,

Former Member
0 Kudos

Hello,

hier ist JSON Output file :

{

  "d" : {

    "EntitySets" : [

      "MaterialSet"

    ]

  }

}

Regards,

Amyn

Former Member
0 Kudos

initially I had

...

                   var aData = oModel.getProperty("/d/results/");   
                   oModel1.setData({ modelData : aData });   
   
                   oTable.setModel(oModel1);  
Joseph_BERTHE
Active Contributor
0 Kudos

so the path should be : /d/EntitySets/MaterialSet

Joseph_BERTHE
Active Contributor
0 Kudos

uhm, your json should be something like this ?

{

  "d" : {

    "EntitySets" : [

      {  "attr1" : "value1"    },{  "attr1" : "value2"    }, ....

    ]

  }

}

What looks like your  "MaterialSet" ?

Former Member
0 Kudos

Name             Name Entity type

MaterialSet    Material

And Metadata:

-<EntityType sap:content-version="1" Name="Material">

-<Key>

<PropertyRef Name="Matnr"/>

</Key>

<Property Name="Matnr" sap:label="Material" MaxLength="18" Nullable="false" Type="Edm.String"/>

<Property Name="Maktx" sap:label="Bezeichnung" MaxLength="40" Nullable="false" Type="Edm.String" sap:filterable="false" sap:sortable="false" sap:updatable="false" sap:creatable="false"/>

</EntityType>

Thanke for your Help !