Basic OnsenUI Configuration Method

Asked 1 years ago, Updated 1 years ago, 76 views

I'm a complete Monaca beginner.Sorry for the rudimentary question.
Using OnsenUI without a controller etc.
I wrote the function using JS as usual with onclick etc.
I was able to switch pages with Pushpage, but on the page I switched to
The DOM could not be rewritten.
How do I display data for DOMs loaded after Psuhpage?

monaca onsen-ui

2022-09-30 16:16

1 Answers

I'm also a beginner, so from a beginner's point of view...
I can't say for sure because I don't have the code, but it might be a problem when JavaScript runs.If you put control over the DOM before each element is built, such as the moment you touch the page-switch button, you will not get the desired result.
It was a trial and error, but I dealt with it by setting up the following event listeners:

 document.addEventListener('pageinit', function(page){
if(page.target.id=="Page1"){
    initPage1(); // Page 1 initialization process
  } 
if(page.target.id=="Page2"){
    initPage2(); // Page 2 initialization process
  }
 }

page.target.id=="Page1" include the Id specified in <ons-page id="Page1">.

"pageinit" is an event that takes place after each element is built, so I think you can access each element even if it is pushed.


2022-09-30 16:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.