【发布时间】:2014-05-23 12:49:04
【问题描述】:
我正在尝试使用 $.eventslisttable.setData([]); 重置 Alloy 中的表我怎么会得到 Uncaught ReferenceError: $ is not defined.
该表是在alloy.js 下创建的,我正在尝试从index.js 完成重置
alloy.js
// create tab group
var tabGroup = Titanium.UI.createTabGroup();
//
// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({
title: 'Tab 1',
backgroundColor: '#fff'
});
var tab1 = Titanium.UI.createTab({
icon: 'KS_nav_views.png',
title: 'Tab 1',
window: win1
});
//var button = Titanium.UI.createButton({
// color: '#999',
// title: 'Show Modal Window',
// width: 180,
// height: 35
//});
//
// create controls tab and root window
//
var win2 = Titanium.UI.createWindow({
title: 'Tab 2',
backgroundColor: '#fff'
});
var tab2 = Titanium.UI.createTab({
icon: 'KS_nav_ui.png',
title: 'Tab 2',
window: win2
});
//
// add events table
//
var eventslisttable = Titanium.UI.createTableView({});
win2.add(eventslisttable);
//
//watchbutton setup
//
var buttonShowmap = Titanium.UI.createButton({
title: 'Showmap',
top: 10,
width: 100,
height: 50
});
var buttonshowEventslist = Titanium.UI.createButton({
title: 'showEventslist',
top: 60,
width: 100,
height: 50
});
win2.add(buttonShowmap);
win2.add(buttonshowEventslist);
//
// add tabs
//
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
//
// open tab group
//
tabGroup.open({navBarHidden:true});
index.js
function showMapview(e) {
console.log("showMapview");
// wipe list view
$.eventslisttable.setData([]);
console.log("showMapview Internal");
// Add the mapview
var mapview = Titanium.Map.createView({
mapType : Titanium.Map.STANDARD_TYPE,
region : {
latitude : Alloy.Globals.LAT,
longitude : Alloy.Globals.LNG,
latitudeDelta : 0.01,
longitudeDelta : 0.01
},
animate : true,
regionFit : true,
userLocation : true,
height : 200
});
// Insert a row in first index of the table that has the mapview in it
var row = Ti.UI.createTableViewRow();
row.add(mapview);
$.eventslisttable.insertRowBefore(1, row);
// Handle click events on any annotations on this map.
mapview.addEventListener('click', function(evt) {
Ti.API.info("Annotation " + evt.title + " clicked, id: " + evt.annotation.myid);
// Check for all of the possible names that clicksouce
// can report for the left button/view
if (evt.clicksource == 'leftButton' || evt.clicksource == 'leftPane' || evt.clicksource == 'leftView') {
Ti.API.info("Annotation " + evt.title + ", left button clicked.");
}
});
};
【问题讨论】:
-
$在哪里定义?您是否忘记在此代码之前包含一个库? -
没有迹象表明您在您提供的任何代码中定义了该名称的变量。您只需尝试在其上使用属性。
-
var eventslisttable = Titanium.UI.createTableView({});在alloy.js 中定义的应该是全局可见的。我的理解是 $ 是控制器( index.js )能够处理现有表而不是删除或重新创建的方式。
标签: javascript titanium-alloy uncaught-exception