on 08-16-2016 10:51 AM
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
line 22: <Table ... items="{/suggestionData}">
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK, next try;)
You have to implement the method onInit() for your controller, e.g.
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 () {
var demoJSONModel = new sap.ui.model.json.JSONModel();
var oData={
suggestionData:[{
'WORD':"test1",
'SUGGESTION':"...test..."
},{
'WORD':"test2",
'SUGGESTION':"...test..."
}]
};
demoJSONModel.setData(oData);
this.getView().setModel(demoJSONModel);
};
});
});
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"
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.