繁体   English   中英

如何在Titanium中链接js页面?

[英]How to link js pages in Titanium?

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

“消息:未捕获的TypeError:对象不是函数[ERROR]:TiExceptionHandler :(主)[0,654]-源:new Window()。open();”

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

我的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
 };

抱歉,如果我提出问题的方式不清楚。 谁能告诉我我哪里出问题了? 提前致谢 :)

请密切注意您的错误消息:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM