javascript Appcelerator Titanium:如何使用窗口的 onLoad 事件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5550119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 17:35:38  来源:igfitidea点击:

Appcelerator Titanium: How to use the onLoad event of an Window?

javascriptandroidtitanium

提问by theJava

mainWin.pageLoad=false;
mainWin.addEventListener('load', function(e) {
  if(mainWin.pageLoad) {
    mainWin.open();    
     } else {
      mainWin.close();    
      var LoginWindow = Titanium.UI.createWindow({ 
        title : 'Login',  
        url:'Login.js'   
      });
   LoginWindow.open();
  }
});

This is my app.js file. If the pageLoad variable holds the boolean value true, then i need to navigate to mainWin {Which is the current Window}else i need to go to Login Page.

这是我的 app.js 文件。如果 pageLoad 变量保持布尔值 true,那么我需要导航到 mainWin{Which is the current Window}否则我需要转到登录页面。

回答by Thalaivar

    var LoginWindow = Titanium.UI.createWindow ({
      backgroundColor:'#1E563F',
      url:'Login.js',
    });


    mainWin.addEventListener('open', checkPage);
        mainWin.pageLoad = false;

        function checkPage() {  
           if(mainWin.pageLoad) {
             mainWin.open();
           } else {
             mainWin.close();
             LoginWindow.open();
           }
        }

  mainWin.open();

This should work....

这应该工作......

回答by Zakaria

Did you try to put your code like this ?

你试过把你的代码写成这样吗?

mainWin.pageLoad = false;
mainWin.addEventListener('load', function(e) {
  if(mainWin.pageLoad) {
    mainWin.open();    
   } else {
      mainWin.close();    
      var LoginWindow = Titanium.UI.createWindow({ 
        title : 'Login',  
        url:'Login.js'   
      });
   LoginWindow.open();
  }
});

回答by gads

The reason is probably that the the variable is updated to true before the event is dispatched. Did you try to print to console the mainWin.pageLoad value? Where do you update the variable to true?

原因可能是该变量在调度事件之前更新为 true。您是否尝试打印以控制台 mainWin.pageLoad 值?你在哪里更新变量为真?

回答by Aaron Saunders

try using the focusevent instead of the load event.

尝试使用focus事件而不是加载事件。