Skip to Content

No JSON data displayed in Table

Hey,

I try to use a table with JSON data, but my table is still after few attempts (using examples from internet) empty.

I hope you can find my mistake(s)

Here is my code:

<!DOCTYPE html>
<html>
<head>
       <meta http-equiv="X-UA-Compatible" content="IE=edge">
       <meta charset="utf-8">
       <title>Rechtschreibprüfung</title>
       <script
            id="sap-ui-bootstrap"
            src="https://cloudportaltrial-p1941901642trial.hanatrial.ondemand.com/ui5-dist/resources/sap-ui-core.js"
            data-sap-ui-theme="sap_bluecrystal"
            data-sap-ui-libs="sap.m"
            data-sap-ui-compatVersion="edge"
            data-sap-ui-preload="async"
            data-sap-ui-xx-bindingSyntax="complex"
            data-sap-ui-resourceroots='{
                 "sap.ui.demo.wt": "./"
            }'>
       </script>

       <link rel="stylesheet" type="text/css" href="style.css">

       <script>
            sap.ui.getCore().attachInit(function () {
            sap.ui.xmlview({
            viewName: "sap.ui.demo.wt.view.App"
                 }).placeAt("content");
            });
       </script>
</head>
<body class="sapUiBody" id="content">
    
</body>
</html>

<mvc:View
  controllerName="sap.ui.demo.wt.controller.App"
  xmlns="sap.m"
  xmlns:mvc="sap.ui.core.mvc"
  xmlns:l="sap.ui.layout"
  xmlns:core="sap.ui.core">
       <l:VerticalLayout width="100%" >
            <l:content>
                 <Button
                      text="Prüfung"
                      press="checkText"
                      id = "startButton"
                      width = "auto"
                      class="sapUiResponsiveMargin">
                 </Button>
                 <Panel class="sapUiResponsiveMargin" width = "auto" id="panel2">
                      <headerToolbar>
                           <Toolbar>
                                <Title level="H2" text="Vorschläge" />
                           </Toolbar>
                      </headerToolbar>
                      <Table id="suggestionTable" items="{path:'/suggestionData'}">
                         <columns>
                             <Column>
                                 <Label text="Wort"></Label>
                             </Column>
                             <Column>
                                 <Label text="Vorschläge"></Label>
                             </Column>
                         </columns>
                         <items>
                             <ColumnListItem>
                                 <cells>
                                     <ObjectIdentifier title="{WORD}" text="{WORD}"></ObjectIdentifier>
                                 </cells>
                                      <Text text="{SUGGESTION}"></Text>
                             </ColumnListItem>
                         </items>
                      </Table>
                </Panel>
            </l:content>
       </l:VerticalLayout>
</mvc:View>

sap.ui.define([
  "sap/ui/core/mvc/Controller",
  "sap/m/MessageToast"
], function(Controller, MessageToast) {
  "use strict";
  return Controller.extend("sap.ui.demo.wt.controller.App", {
  checkText: function() {
  var here = this;
  here.getWhitelist();
  here.getCorrections();
  here.createSuggestionTable();
  },
  createSuggestionTable: function() {
  var oData={
         suggestionData:[{
             'WORD':"test1",
             'SUGGESTION':"...test..."
         },{
             'WORD':"test2",
             'SUGGESTION':"...test..."
         }]
  };
  var demoJSONModel = new sap.ui.model.json.JSONModel();
            demoJSONModel.setData(oData);
            sap.ui.getCore().getElementById("suggestionTable").setModel(demoJSONModel);
  }
  });
});

Thanks in advance 😊

Tim

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Aug 16, 2016 at 10:36 AM

    line 22: <Table ... items="{/suggestionData}">

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Tim Kudla

      The controller may look like this:

      sap.ui.define(['sap/ui/core/mvc/Controller','sap/ui/model/json/JSONModel'],
           function(Controller, JSONModel) {
           "use strict";
           return Controller.extend("sap.ui.demo.wt.controller.App", {
      
           onInit: function () {
                this.model = new sap.ui.model.json.JSONModel({
                     suggestionData:[]
                });
                this.getView().setModel(this.model);
           },
      
           checkText: function() {
                // this.getWhitelist();  
                // this.getCorrections();
                this.updateSuggestionData();  
           },  
      
           updateSuggestionData: function() {
                var aSuggections = [{  
                               'WORD':"test1",  
                               'SUGGESTION':"...test..."  
                          },{  
                               'WORD':"test2",  
                               'SUGGESTION':"...test..."  
                          }];
                this.model.setProperty("/suggestionData", aSuggections);
           }
      
           });
      });
      

      AND your view: line 11 should be (start with dot)

      press=".checkText"
      
  • Posted on Aug 16, 2016 at 01:18 PM

    Discussion successfully moved from SAP HANA Cloud Platform Developer Center to SAPUI5 Developer Center

    as the more appropriate community for this question and status reset to Not Answered from Assumed Answered (which should not be used).

    Regards, Mike (Moderator)

    SAP Technology RIG

    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.