on 03-20-2018 1:27 PM
Hello,
sorry for my English 🙂
I've an app with component that load a view/controller
In the controller init and other methods I need to load odata from server (with odata read) but in the success handler I can't get the view to bind my new data to the model of a specific control.
I can do anythings going directly to the control by full ID (like '__xmlview0--companies', for example) with a sap.ui.getCore().byId('__xmlview0--companies') by this isn't the right way, I would like to get the control directly
If I use this.getView() in the read success function, "this" isn't the controller but the odataModel object.
If this can help:
root.view.xml:
<Input id="companies" showSuggestion="true" showValueHelp="true"/>
root.controller.js
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/core/format/NumberFormat"
], function (Controller, NumberFormat) {
"use strict";
return Controller.extend("AppName.controller.root", {
onInit: function () {
var myOdataModel = new sap.ui.model.odata.ODataModel('/mock/', true);
myOdataModel.read('COMPANY', null, null, false, function (inutile, json) {
var data = json.data.results;
datas.companies = data;
var model = new sap.ui.model.json.JSONModel();
model.setData(datas.companies);
var companiesInput = this.getView().byId('companies');
companiesInput.setModel(model);
});
Component.js:
sap.ui.define([
"sap/ui/core/UIComponent",
"sap/ui/Device"
], function (UIComponent, Device) {
"use strict";
return UIComponent.extend("AppName.Component", {
metadata: {
manifest: "json"
},
init: function () {
UIComponent.prototype.init.apply(this, arguments);
}
});
});
sap.ui.define(["sap/ui/core/mvc/Controller","sap/ui/core/format/NumberFormat"],function(Controller, NumberFormat){"use strict";return Controller.extend("AppName.controller.root", {
onInit:function(){
var that=this;
var myOdataModel =newsap.ui.model.odata.ODataModel('/mock/', true);
myOdataModel.read('COMPANY',null,null, false,function(inutile, json){
var data= json.data.results;
datas.companies =data;
var model =newsap.ui.model.json.JSONModel();
model.setData(datas.companies);
var companiesInput = that.getView().byId('companies');
companiesInput.setModel(model);});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.