0
我一直得到一個簡單的二手機項目出現以下錯誤:如何添加一個js文件中的鈦移動項目
Location:
app.js
Message:
Uncaught ReferenceError: tab2 is not defined
Source: tabGroup.addTab(tab2);
這裏是我的app.js文件中的代碼:
// create tab group
var tabGroup = Titanium.UI.createTabGroup();
// create the window
var win1 = Ti.UI.createWindow({
width: 320,
height: 440,
top: 0,
left: 0,
backgroundImage: 'background.png',
title: 'loan calculator',
barImage: 'navbar.png'
});
// creat the view, this will hold all of our UI controls
// note the hight of this view is the height of the window
// minus 134px for the status bar and padding and adjusted for navbar
var view = Ti.UI.createView({
width: 300,
height: win1.height - 134,
left: 10,
top: 10,
backgroundColor: '#fff',
borderRadius: 5
});
// we will give the logo a left margin so it centers neatly
// within our view
var _logoMarginLeft = (view.width - 253)/2;
// now let's add our logo to an imageview and add that to our
// view object
var logo = Ti.UI.createImageView({
backgroundImage: 'logo.png',
width: 253,
height: 96,
left: _logoMarginLeft,
top: 0
});
view.add(logo);
// add the view to our window
win1.add(view);
// add the first tab and attach our window object (win1) to it
var tab1 = Ti.UI.createTab({
icon: 'icon_calculator.png',
title: 'Calculate',
window: win1
});
// create the second window for settings tab
var win2 = Ti.UI.createWindow({
width: 320,
height: 440,
top: 0,
left: 0,
backgroundImage: 'background.png',
url: 'window2.js',
title: 'Settings',
barImage: 'navbar.png'
});
// now add the tabs to our tabGroup object
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
// open the tabgroup to launch the app
tabGroup.open();
這裏是我的window2.js代碼:
// add the second tab and attach our external window object
// (win2/window2.js) to it
var tab2 = Ti.UI.createTab({
icon: 'icon_settings.png',
title: 'Settings',
window: win2
});
這又如何解決?
我正在測試Appcelerator鈦智能手機應用程序開發食譜書中的代碼。我有一個單獨的文件,但從來沒有一個選項卡編程窗口,所以我只是想正確地做。 –