Quantcast
Channel: SCN : All Content - SAPUI5 Developer Center
Viewing all articles
Browse latest Browse all 6178

Can't use app.to

$
0
0

Hi Community,

 

I,m trying to build a navigaton for my Solution.
Its a Page with some tiles. I want those tiles to work as navigation points into other pages.

 

Whenever i try to use my code, its tells me "Uncaught TypeError: app.to is not a function".
I'm not able to figure out why its not working, because i already used this method for and comparable Navigaton.At first, here is my Code:

 

The index.html:

 

                    
 

Here my controller (entry.controller.js)

jQuery.sap.require("jquery.sap.history");
jQuery.sap.require("sap.m.InstanceManager");
sap.ui  .controller(  "view.entry",  {  onInit : function() {  var historyDefaultHandler = function(navType) {  if (navType === jQuery.sap.history.NavType.Back) {  this.navBack(this.getDefaultPage());  } else {  this.navTo(this.getDefaultPage(), null, false);  }  };  var historyPageHandler = function(params, navType) {  if (!params || !params.id) {  jQuery.sap.log.error("invalid parameter: "  + params);  } else {  if (navType === jQuery.sap.history.NavType.Back) {  this.navBack(params.id);  } else {  this.navTo(params.id, params.data, false);  }  }  };  jQuery.sap.history({  routes : [ {  // This handler is executed when you navigate  // back to the history state on the path "page"  path : "page",  handler : jQuery  .proxy(historyPageHandler, this)  } ],  // The default handler is executed when you navigate  // back to the history state with an empty hash  defaultHandler : jQuery.proxy(  historyDefaultHandler, this)  });  // subscribe to event bus  var bus = sap.ui.getCore().getEventBus();  bus.subscribe("nav", "to", this.navHandler, this);  bus.subscribe("nav", "backToPage", this.navHandler,  this);  bus.subscribe("nav", "back", this.navHandler, this);  bus.subscribe("nav", "virtual", this.navHandler, this);  this.bus = bus;  },  doNavOnSelect : function(event) {  this.bus.publish("nav", "to", {  id : event  });  },  navHandler : function(channelId, eventId, data) {  var app = this.getView();  if (eventId === "to") {  this.navTo(data.id, data.data, true);  } else if (eventId === "backToPage" && data && data.id) {  app.backToPage(data.id);  } else if (eventId === "back") {  if (data && data.id) {  this.navBack(data.id);  } else {  jQuery.sap.history.back();  }  } else if (eventId === "virtual") {  jQuery.sap.history.addVirtualHistory();  } else {  jQuery.sap.log  .error("'nav' event cannot be processed. There's no handler registered for event with id: "  + eventId);  }  },  navTo : function(id, data, writeHistory) {  if (id === undefined) {  // invalid parameter  jQuery.sap.log  .error("navTo failed due to missing id");  } else {  var app = this.getView();  // navigate in the app control  app.to(id, "slide", data);  }  },  navBack : function(id) {  if (!id) {  // invalid parameter  jQuery.sap.log  .error("navBack - parameters id must be given");  } else {  // close open popovers  if (sap.m.InstanceManager.hasOpenPopover()) {  sap.m.InstanceManager.closeAllPopovers();  }  // close open dialogs  if (sap.m.InstanceManager.hasOpenDialog()) {  sap.m.InstanceManager.closeAllDialogs();  jQuery.sap.log  .info("navBack - closed dialog(s)");  }  // ... and navigate back  var app = this.getView().app;  var currentId = (app.getCurrentPage()) ? app  .getCurrentPage().getId() : null;  if (currentId !== id) {  app.backToPage(id);  jQuery.sap.log.info("navBack - back to page: "  + id);  }  }  }  });

and my view (entry.view.js):

sap.ui.jsview("view.entry",  {  getControllerName : function() {  return "view.entry";  },  createContent : function(oController) {  // set MainPage  var mainTileContainer = new sap.m.TileContainer(  mainTileContainer, {});  var menuModel = new sap.ui.model.json.JSONModel(  "model/menuNoI18n.json");  menuModel.attachRequestCompleted(null, function() {  function navFn(target) {  return function() {  oController.doNavOnSelect(target);  }  }  var data = null, m = 0, menu = null;  data = menuModel.getData();  if (data && data.Menu) {  for (m = 0; m < data.Menu.length; m++) {  menu = data.Menu[m];  mainTileContainer.addTile(new sap.m.StandardTile({  icon : menu.icon,  title : menu.title,  info : menu.description,  press : navFn(menu.targetPage)  }));  }  }  });  var app = new sap.m.Page({  setShowHeader : true,  title : "Welcome w/out i18n",  footer : new sap.m.Bar({  contentMiddle : [ new sap.m.Link("version", {  text : "0.20"  }) ]  })  });  app.setEnableScrolling(false);  app.setShowHeader(true);  app.addContent(mainTileContainer);  return app;  }  });

 

In the debugger I were able to see that the Problem comes frome line 106 [  app.to(id, "slide", data); ]

 

I hope someone got an idea why app.to cant be found here.

 

Regards
Dain


Viewing all articles
Browse latest Browse all 6178

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>