2013-07-25 117 views
0

App.js我如何加載一個按鈕點擊另一個js文件中鈦

(function() {  
    Window = require('ui/tablet/ApplicationWindow'); 

    } 
    new Window().open(); 
    })(); 

從那裏ApplicationWindow.js被加載。
ApplicationWindow.js

function ApplicationWindow() { 
    //load component dependencies 
    var FirstView = require('ui/common/FirstView'); 

    //create component instance 
    var self = Ti.UI.createWindow({ 
     backgroundColor:'#ffffff' 
    }); 
    var win2 = Titanium.UI.createWindow({ 
    backgroundColor: 'red', 
    title: 'Red Window' 
    }); 

    //construct UI 
    var firstView = new FirstView(); 
    var nav = Titanium.UI.iPhone.createNavigationGroup({ 
    window: win2 
    }); 
    win2.add(firstView); 
    self.add(nav); 
    self.open(); 
    //self.add(firstView); 
    if (Ti.Platform.osname === 'ipad') { 
     self.orientationModes = [Ti.UI.LANDSCAPE_LEFT] ; 
    }; 
    return self; 
} 

//make constructor function the public component interface 
module.exports = ApplicationWindow; 

獲得帶有2個文本框的視圖和在FirstView.js .The視圖都有標題紅窗口的導航條的按鈕登錄。我想在loginButton Click上加載Home.js。 這裏是loginButtonClick代碼:

loginButton.addEventListener ('click', function(e){ 
      //navigate to Home.js 
     }); 

我怎會that.Can請人幫助我。

回答

1

試試下面的方法在當前文件

loginButton.addEventListener('click', function(e){ 
    var win = Ti.UI.createWindow({ 
     backgroundColor : 'white', 
     url    : 'home.js' //Path to your js file 
    }); 
    win.open(); 
}); 

home.js

var myWin = Ti.UI.currentWindow; 
//You can add your controls here and do your stuff. 
// Note that never try to open myWin in this page since you've already opened this window 

您還可以試試下面的方法

方法2

//In your current page 
loginbutton.addEventListener('click', function(e) { 
    var Home = require('/ui/common/Home'); 
    var homePage = new Home(); 
    homePage.open(); 
}); 

你Home.js文件

function Home() { 
    var self = Ti.UI.createWindow({ 
     layout : 'vertical', 
     backgroundColor:'white' 
    }); 
    //Do your stuff here 
    //Add other controls here 

    return self; 
} 
module.exports = Home; 

this answer,這也是一樣的你的問題

相關問題