-1

I am trying to reset a table in Alloy using $.eventslisttable.setData([]); how ever I get Uncaught ReferenceError: $ is not defined.

The table is been created under alloy.js and I am trying to complete the reset from 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.");
            }
        });
};
Origineil
  • 3,108
  • 2
  • 12
  • 17
Terran Brown
  • 509
  • 10
  • 25
  • 3
    Where is `$` defined? Did you forget to include a library before this code? – David May 23 '14 at 12:51
  • There's no sign of you defining a variable of that name in any of the code you've supplied. You just try to use properties on it. – Quentin May 23 '14 at 12:52
  • var eventslisttable = Titanium.UI.createTableView({}); is defined in the alloy.js should should be seen globally. My understanding is that $ is the way the controller ( index.js ) is able to address the existing table rather than deleting or re-creating. – Terran Brown May 23 '14 at 12:56

1 Answers1

0

So the answer was to remove $ so I was steered in the wrong direction.

Thanks for all your help.

Terran Brown
  • 509
  • 10
  • 25