未捕获的引用错误在钛

Uncaught Reference error in Titanium

本文关键字:错误 引用      更新时间:2023-09-26

我在包含来自另一个文件的函数时遇到了麻烦。我有两个文件app.jsresponsive.js在响应。js我有这个:

    // 100%
    var per100 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 1.0); 
    // 90%
    var per90 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.9); 
    // 80%
    var per80 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.8); 
    // 60%
    var per50 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.6); 
    // 50%
    var per50 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.5); 
    // 40%
    var per40 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.4);
    // 25%
    var per25 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.25); 
    // 10%
    var per10 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.10); 
    // 5%
    var per5 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.5); 
    // 1%
    var per1 = Math.floor(Titanium.Platform.displayCaps.platformWidth * 0.1);

和在app.js文件我有这个:

// include needed files
Ti.include('responsive.js');

//Create the screen
//The home screen
var homeWindow = Ti.UI.createWindow({
  exitOnClose: true,
  fullscreen: false,
  title: 'Advanced'
});
var homeView = Ti.UI.createView({
  backgroundColor: 'white'
});
var homeLabel = Ti.UI.createLabel({
    top: 20,
    left: 30,
    height: 30,
    text: 'Login or register to start',
    color: 'black',
    font: {fontSize: 18}
});
var homeLoginButton = Ti.UI.createButton({
    title: 'test',
    backgroundColor: 'red',
    top: 55,
    left: 30,
    width:per60,
    height: 30,
    color: 'black',
    font: {fontSize: 14} 
});
var homeRegisterButton = Ti.UI.createButton({
    title: 'test2',
    backgroundColor: 'blue',
    top: 55,
    left: 180,
    width:per60,
    height: 30,
    color: 'black',
    font: {fontSize: 14} 
});
//Creating the application
//Home screen
homeWindow.add(homeView);
homeView.add(homeLabel);
homeView.add(homeLoginButton);
homeView.add(homeRegisterButton);
homeWindow.open();

一切都很简单但是每次我试图启动应用程序时都会出现这个错误

Uncaught Reference error: per60 is not defined

如何解决这个问题?

你似乎有两次:

var per50

var per60
第一个文件