javascript - openui5/sapui5: Change parts of a page controlled by router -


i implement master-detail-like ui5 application without using splitapp-control in sap.m. instead want have page fixed content on left , <navcontainer> on right. based on url (router) change content of <navcontainer> only - not entire page.

so far initial page renders correctly. if cange url #trans whole page changes previewtransaction.view.xml, not <navcontainer> part.

whats wrong?

index.html:

<!doctype html> <html>   <head>     <meta http-equiv='x-ua-compatible' content='ie=edge' />     <meta http-equiv='content-type' content='text/html;charset=utf-8' />     <title>hello ui5!</title>      <script id='sap-ui-bootstrap' type='text/javascript'        src='https://openui5beta.hana.ondemand.com/resources/sap-ui-core.js'       data-sap-ui-libs="sap.m"       data-sap-ui-theme="sap_bluecrystal"       data-sap-ui-bindingsyntax="complex"       data-sap-ui-frameoptions='allow'     >     </script>      <script>          sap.ui.getcore().attachinit(function () {             sap.ui.require([], function () {                  var app = new sap.m.app("appid");                 appglobals.app = app;                 var rootview = new sap.ui.view({id: "mainid", viewname: "./approot", type: sap.ui.core.mvc.viewtype.xml});                 app.addpage(rootview); // app contains views                 app.placeat("content");                  // setup router                 jquery.sap.require("sap.ui.core.routing.router");                 jquery.sap.require("sap.ui.core.routing.hashchanger");                 jquery.sap.require("./routes"); // load ./routes.js                 var router = new sap.ui.core.routing.router(myroutes, myroutesdefaultsettings, null, mytargetsconfig); // myroutes defined in routes.js                 router.initialize();             });         });   </script>    </head>   <body class='sapuibody' id="content">   </body> </html> 

approot.view.xml:

<mvc:view xmlns="sap.m" xmlns:l="sap.ui.layout">     <page>          <content>             <l:verticallayout id="containerlayout" width="100%" height="100%">                 <l:blocklayout id="blocklayout">                     <l:blocklayoutrow>                         <l:blocklayoutcell>                              <!-- 'master' -->                             <mvc:xmlview viewname="xx.views.searchcontrolpanel"></mvc:xmlview>                          </l:blocklayoutcell>                         <l:blocklayoutcell width="3">                              <!-- 'detail' -->                             <navcontainer id="nc_previewcontent" height="100%" navigate="nc_nav">                                 <mvc:xmlview viewname="./preview"></mvc:xmlview>                             </navcontainer>                          </l:blocklayoutcell>                     </l:blocklayoutrow>                 </l:blocklayout>             </l:verticallayout>         </content>     </page> </mvc:view> 

routes.js:

var myroutesdefaultsettings = {     viewtype: "xml",     cleartarget: true };  var myroutes = [     {         name: "main",         pattern: "",         target: "welcome"     },     {         name: "transactions",         pattern: "trans", // handle #trans url endings         target: "transactions"     } ];  var mytargetsconfig = {      welcome: {         viewname: "./approot",         controlid: "appid",         controlaggregation: "pages",         clearaggregation: false     },     transactions: {         viewname: "./previewtransactions",         controlid: "nc_previewcontent", // id of navcontainer in pproot.view.xml         controlaggregation: "pages", // aggregation of navcontainer named 'pages'         clearaggregation: false     }  }; 

the problem id defined in router (routes.js) - controlid:"nc_previewcontent". since navcontainer sitting within approot view ( id -main), correct id of navcontainer (since ids of controls in xml views prefixed view id):

 controlid: "mainid--nc_previewcontent" 

i changed code above id, made following changes:

  1. change id of controlid in router : mainid--nc_previewcontent
  2. changed router sap.ui.core.routing.router sap.m.routing.router

it's working expected ( navcontainer changed). code follows below:

index.html

<script>         sap.ui.localresources("/");          sap.ui.getcore().attachinit(function () {             sap.ui.require([], function () {                  var app = new sap.m.app("appid");                 //appglobals.app = app;                 var rootview = new sap.ui.view({id: "mainid", viewname: "com.sap.approot", type: sap.ui.core.mvc.viewtype.xml});                 app.addpage(rootview); // app contains views                 app.placeat("content");                  // setup router                 jquery.sap.require("sap.m.routing.router");                 jquery.sap.require("sap.ui.core.routing.hashchanger");                 jquery.sap.require("com.sap.routes"); // load ./routes.js                 var router = new sap.m.routing.router(myroutes, myroutesdefaultsettings, null, mytargetsconfig); // myroutes defined in routes.js                 router.initialize();              });         });         </script> 

routes.js

var myroutes = [     {         name: "main",         pattern: "",         target: "welcome"     },     {         name: "second",         pattern: "second", // handle #trans url endings         target: "second"     } ];  var mytargetsconfig = {      welcome: {         viewname: "com.sap.viewright",         controlid: "mainid--nc_previewcontent",         controlaggregation: "pages",         clearaggregation: false     },     second: {         viewname: "com.sap.viewright2",         controlid: "mainid--nc_previewcontent", // id of navcontainer in pproot.view.xml         controlaggregation: "pages", // aggregation of navcontainer named 'pages'         clearaggregation: false     }  }; 

let me know if need additional information.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -