on 11-23-2017 1:45 AM
Hello:
I used the example at the following link to try to set, and then read, a model in the Core.
The code in the First (sending) Controller is:
onAddPressed: function(oEvent) {
var oCustomerID = this.getView().byId("CustomerID").getText();
var modelParameters = {};
modelParameters.CustomerID = oCustomerID;
this.customer.setData(modelParameters);
sap.ui.getCore().setModel(this.customer);
var oBindingContext = oEvent.getSource().getBindingContext();
var oCustomerModel = sap.ui.getCore().getModel('/CustomerID');
},
onInit: function() {
this.customer = new sap.ui.model.json.JSONModel();
this.mBindingOptions = {};
this.oRouter = sap.ui.core.UIComponent.getRouterFor(this);
this.oRouter.getTarget("Customer").attachDisplay(jQuery.proxy(this.handleRouteMatched, this));
}
And in the Second (receiving) Controller is:
onAddPressed: function(oEvent) {
var oCustomerNumber = sap.ui.getCore().getModel("/CustomerID");
}
When I stop on the first line in the receiving Controller, oCustomerNumber is undefined.
Am I forgetting to do something?
Hi,
In First controller set value like this.
ap.ui.getCore().setModel(this.customer, "MdlName");
At receiving controller like this.
sap.ui.getCore().getModel("MdlName");
Try this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You shouldn't really set data in the core. Why don't you use routing?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It isn't my preference, but seem to be an expedient way to accomplish what I needed (passing a value from one view to another). If I read the code in the sample correctly, you can pass parameters when routing, is that true? (I am new to SAP UI5). I will try to find some additional tutorials, but that seems like a good approach, too!
Hi Ian ,
Write below code in second controller . This would return all the data that you want in this controller
var oCustomerNumber = sap.ui.getCore().getModel( );
var aData = oCustomerNumber.getData();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Ian,
Are you sure this line works? Have you checked the returning value?
var oCustomerID = this.getView().byId("CustomerID").getText();
I assume that the element assigned by CustomerID is sap.ui.commons.TextField. Hence, you should change your code to
var oCustomerID = this.getView().byId("CustomerID").getValue();
Regards,
Tri
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
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.