Reputation: 199
i want to bind a global Model and access this in different xml views but it always shows no content.
In the Controller i bind the data this way...
sap.ui.define([
'jquery.sap.global',
'sap/ui/core/mvc/Controller',
'sap/ui/model/json/JSONModel'
], function (jQuery, Controller, JSONModel) {
"use strict";
return Controller.extend("sap.ui.demo.controller.DatasourceManagement", {
onInit: function() {
var datasourcesModel = new JSONModel('/api/datasources');
sap.ui.getCore().setModel(datasourcesModel, 'datasources');
//this.getView().setModel(datasourcesModel,'datasources');
},
....
And in the View i try to access the data this way...
mvc:View xmlns="sap.m" xmlns:tnt="sap.tnt" xmlns:l="sap.ui.layout"
xmlns:mvc="sap.ui.core.mvc"
controllerName="sap.ui.demo.controller.DatasourceManagement">
<Page showHeader="false" enableScrolling="true" class="sapUiContentPadding test"
showNavButton="false">
<content>
<Table id="datasourceTable"
items="{path: 'datasources>',
sorter: {
path: 'id'
}}"
....
What is the problem with my code?
-------EDIT 1------------- The URL "/api/datasources" returns an array of entries:
[
{
"id": 1,
"name": "FTPSERVER",
"hostname": "test.de",
"port": 21,
"username": "username",
"password": "password"
},
{
"id": 2,
"name": "FTPSERVERasdasdasdadsads1111111",
"hostname": "test.de",
"port": 21,
"username": "username",
"password": "password"
},
{
"id": 3,
"name": "FTPSERVER",
"hostname": "test.de",
"port": 21,
"username": "username",
"password": "password"
}
]
Upvotes: 0
Views: 1256
Reputation: 199
Now I got the solution...
When I bind the model to the component, it works:
this.getOwnerComponent().setModel(datasourcesModel, "datasources");
And in the view, I can bind the model that way:
<Table items="{datasources>/}" />
Upvotes: 0
Reputation: 5206
I think it is because of your Table items binding path, specifically you should change it to 'datasources>/' instead of 'datasources>'.
Based on the code snippet that you have shown, I assume that "/api/datasources" returns an array/map of entries.
Working with the assumption that the HTTP request gives you back a non-empty array (which you should check in the Developer Console --> Network tab), I see only one problem in your code: the binding path for the Table's items is relative.
In UI5, bindings are of two types:
Absolute bindings are resolved directly, by taking the object at the given path in the model. Relative bindings on the other hand are resolved relatively to some path specified by an ancestor. If there is no other ancestor element binded (absolutely) to something of this JSON Model, then the binding will not be resolved.
Upvotes: 1