Onsen-Ui, not understanding the page stack object

30 Views Asked by At

I am trying to work with the Navigator Object in Onsen. I know how to push pages, remove pages etc. What I can't work out how to retrieve the list of the pages - getPages() - held in the page stack and the current page at the top of the stack getCurrentPage().

Onsen-Ui - Navigator Object Link

I have included a very brief pen - I am new to Onsen having previously used JQM - the latter I would know how to do. I have searched around but to no avail.

[Brief Pen with code and the problem I am having][2]

document.addEventListener('init', function(event) {
  var page = event.target;
  
  alert("Current Page "+page.getCurrentPage+" "+page.getPages+" ");

  if (page.id === 'page1') {
    page.querySelector('#push-button').onclick = function() {
      document.querySelector('#myNavigator').pushPage('page2.html', {data: {title: 'Page 2'}});
      
    };
  } else if (page.id === 'page2') {
    page.querySelector('ons-toolbar .center').innerHTML = page.data.title;
    
    
    
  }
});
<link href="https://unpkg.com/onsenui/css/onsenui.css" rel="stylesheet"/>
<link href="https://unpkg.com/onsenui/css/onsen-css-components.min.css" rel="stylesheet"/>
<script src="https://unpkg.com/onsenui/js/onsenui.min.js"></script>
<script src="https://unpkg.com/jquery/dist/jquery.min.js"></script>
<ons-navigator swipeable id="myNavigator" page="page1.html"></ons-navigator>

<template id="page1.html">
  <ons-page id="page1">
    <ons-toolbar>
      <div class="center">Page 1</div>
    </ons-toolbar>

    <p>This is the first page.</p>

    <ons-button id="push-button">Push page</ons-button>
  </ons-page>
</template>

<template id="page2.html">
  <ons-page id="page2">
    <ons-toolbar>
      <div class="left"><ons-back-button>Page 1</ons-back-button></div>
      <div class="center"></div>
    </ons-toolbar>

    <p>This is the second page.</p>
  </ons-page>
</template>

Any help would be really good.

0

There are 0 best solutions below