如何在Titanium中链接js页面?

时间:2014-07-04 03:15:36

标签: javascript titanium

我是一名初学者,他试图将我的js页面链接在一起,这样当我点击一个按钮时,它将打开另一个js文件的窗口。但是,我不断收到以下错误消息:

"消息:未捕获的TypeError:对象不是函数 [错误]:TiExceptionHandler :(主要)[0,654] - 来源:新窗口()。打开();"

每当我运行我的应用程序时

我app.js文件的代码:

var NavigationController = require('NavigationController').NavigationController,
ApplicationWindow = require('ui/handheld/android/ApplicationWindow').ApplicationWindow;


//create NavigationController which will drive our simple application
var controller = new NavigationController();

//open initial window
controller.open(new ApplicationWindow(this.controller));

我的主/主窗口的代码:(在ApplicationWindow.js中)

//Application Window Component Constructor
exports.ApplicationWindow = function(navController) {
//----------------Main Page-------------------------
var winMainPage = Titanium.UI.createWindow({  
title:'Radio',
backgroundColor: 'transparent',
});
.
.
.
//open second window
var CategoryButton = Titanium.UI.createButton({
bottom: 20,
left: 50,
width: 60,
height: 60,
backgroundImage: '/images/category.png',
backgroundSelectedImage:'/images/category.gif',
backgroundDisabledImage: '/images/categoryoff.gif',
backgroundColor: 'transparent'
});

//Action listener
CategoryButton.addEventListener('click', function() {
navController.open(new PlayMusic(navController));

});



//to exit app by clicking return button
winMainPage.addEventListener('androidback', function(e){
var confirmClear = Titanium.UI.createAlertDialog({


    message:'Exit App?', 
    buttonNames: ['Yes','No']
});
confirmClear.show();
confirmClear.addEventListener('click',function(e) {
    if (e.index === 0) {

     winMainPage.close();


       }
   });
   winMainPage.open();
 });

return winMainPage;

}

第二个窗口中的代码:(在PlayMusic.js中)

exports.PlayMusic = function(navController){
var self = Ti.UI.createWindow({
    backgroundColor:'#ffffff',
    navBarHidden:true,
    exitOnClose:true
  });
  .
  .
  .
  return self;
 }

导航控制器窗口:(NavigationController.js)

exports.NavigationController = function() {
this.windowStack = [];
};

exports.NavigationController.prototype.open = function(/*Ti.UI.Window*/windowToOpen) {
//add the window to the stack of windows managed by the controller
this.windowStack.push(windowToOpen);

//grab a copy of the current nav controller for use in the callback
var that = this;
windowToOpen.addEventListener('close', function() {
    that.windowStack.pop();
});

 //hack - setting this property ensures the window is "heavyweight" (associated with an        Android activity)
windowToOpen.navBarHidden = windowToOpen.navBarHidden || false;

  //This is the first window
  if(this.windowStack.length === 1) {
    if(Ti.Platform.osname === 'android') {
        windowToOpen.exitOnClose = true;
        windowToOpen.open();
    } else {
        this.navGroup = Ti.UI.iPhone.createNavigationGroup({
            window : windowToOpen
        });
        var containerWindow = Ti.UI.createWindow();
        containerWindow.add(this.navGroup);
        containerWindow.open();
    }
   }
  //All subsequent windows
   else {
    if(Ti.Platform.osname === 'android') {
        windowToOpen.open();
    } else {
        this.navGroup.open(windowToOpen);
      }
   }
  };

  //go back to the initial window of the NavigationController
  exports.NavigationController.prototype.home = function() {
 //store a copy of all the current windows on the stack
   var windows = this.windowStack.concat([]);
  for(var i = 1, l = windows.length; i < l; i++) {
    (this.navGroup) ? this.navGroup.close(windows[i]) : windows[i].close();
  }
  this.windowStack = [this.windowStack[0]]; //reset stack
 };

很抱歉,如果我提出问题的方式不清楚。谁能告诉我哪里出错了?在此先感谢:)

1 个答案:

答案 0 :(得分:0)

密切注意您的错误消息:

Message: Uncaught TypeError: object is not a function [ERROR] : TiExceptionHandler: (main) [0,654] - Source: new Window().open();

看起来您可能将Window定义为某个对象,而不是函数。您的共享代码当前不显示Window的声明,但是,根据您的错误消息,我会说检查其类型是开始调试的好地方。如果您可以发布Window声明,那么帮助您会更容易:)