Skip to Content
avatar image
Former Member

How to put navigation function inside odata model read nested success function ?

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){  
    	 })             
	},
	});
});

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    May 08, 2017 at 05:17 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 04, 2017 at 02:40 PM

    Hi Martin, try to pass the context:

    function _OnSuccess() { this.onRedirect() }.bind(this)

    Regards

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi thanks for reply.

      It works _OnSuccess function.

      But I wish to implement this inside press function within my _OnSuccess function.