on 05-04-2017 3:11 PM
Hello experts, I successfully implemented navigation between views inside my shell ui5 application. But problem is that I don't know how implement navigation inside my odata model read success function. My function onRedirect works, but I want to implement this within function _OnSuccess and inside function press for button.
Here is my code snippet from controller:
jQuery.sap.require( 'jquery.sap.resources' );
sap.ui.define([
"sap/ui/core/mvc/Controller",
], function (Controller) {
"use strict";
return Controller.extend("sap.ui.iyc.routepages.First", {
getRouter : function () {
return sap.ui.core.UIComponent.getRouterFor(this);
},
onRedirect : function () {
this.getRouter().navTo("second");
},
onSearch: function(){
var oModel = new sap.ui.model.odata.ODataModel("http://<server>/sap/opu/odata/sap/ZBAPI_ISUFINDER2_SRV/");
var oODataJSONModel = new sap.ui.model.json.JSONModel();
var oView = this.getView();
var oTable = this.getView().byId("idTable");
var oObjecttype = this.getView().byId("inp").getValue();
oModel.read("/BusPartnerSet?$filter=Objecttype eq '",
null,
null,
false,
function _OnSuccess(oData, oResponse){
// create JSON model
var oODataJSONModel = new sap.ui.model.json.JSONModel();
// set the odata JSON as data of JSON model
oODataJSONModel.setData(oData);
// store the model
oTable.setModel(oODataJSONModel);
var oTemplate = new sap.m.ColumnListItem(
cells: [new sap.m.Text({text : '{Buspartner}'}),
new sap.m.Button({text : "Display details", type : "Emphasized",
press: function(e){var obj = e.getSource().getBindingContext().getObject().Buspartner;
var oGlobalJSON = new sap.ui.model.json.JSONModel();
oGlobalJSON.setProperty('/Buspartner', obj);
sap.ui.getCore().setModel(oGlobalJSON, "BuspartnerNumber");
// This is where I want to place navigation
}})
]
});
}})]
});
oTable.bindAggregation("items", { path: "/results", template : oTemplate});
},
function _OnError(oError){
})
},
});
});
I am guessing that you are not able to access the "this" parameter of controller, for access the this.router nav to functionality of component.
so do the below changes.
1. change function _OnSuccess(oData, oResponse){ }.bind(this) - Add .bind(this) at the end of the onSucecss function as it has to access the controller onRedirect function.
2. inside the _onSuccess, call this.onRedirect() function.
Best Regards,
Mahesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mahesh, thank you for reply, but this is the same answer like before. It works within _OnSuccess function but inside this function there is pattern with table where is button and there I wish to implement this navigation. In this source code there is a comment "// This is where I want to impelent navigation."
function _OnSuccess(oData, oResponse){
var oTemplate = new sap.m.ColumnListItem(
{cells: [ new sap.m.Button({text : "Display details", type : "Emphasized",
press: function(e){
var obj = e.getSource().getBindingContext().getObject().Buspartner;
var oGlobalJSON = new sap.ui.model.json.JSONModel();
oGlobalJSON.setProperty('/Buspartner', obj);
sap.ui.getCore().setModel(oGlobalJSON, "BuspartnerNumber");
oGlobalJSON.setDefaultBindingMode("TwoWay");
// This is where I want to impelent navigation.
}
})]
},
oh ok.. bind this to success and now change the press event handler to this:
press: jQuery.proxy(function(e){
// Code
// This is where I want to do Navigation
this.onRedirect();
}, this)
Hi Martin, try to pass the context:
function _OnSuccess() { this.onRedirect() }.bind(this)
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
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.