Search code examples
titaniumtitanium-mobileappceleratorappcelerator-mobile

How to reference a variable inside an exports function?


Novice question: I have a bunch of variables defined inside an exports function, for example:

var movies;

function Tabs(Window) {
    //create module instance
    var self = Ti.UI.createTabGroup({
        activeTabIconTint: '#F4CA53',
        tabsBackgroundColor: '#000000'
    });

     movies = Ti.UI.createTableView({
        data: movieData,
    });

  return self;
}

module.exports = Tabs;

Then over in another js file, that is included in scope, I'm trying to reference that movies variable (tableview). I have tried different things and nothing works:

movies.setData(movieData);
Tabs.movies.setData(movieData);

How can I update the "data" property of the "movies" tableview when I am outside the "Tabs" function?


Solution

  • Can't you just pass it to the Tabs function?

    function Tabs(Window, movieData) {
        //create module instance
        var self = Ti.UI.createTabGroup({
            activeTabIconTint: '#F4CA53',
            tabsBackgroundColor: '#000000'
        });
    
         movies = Ti.UI.createTableView({
            data: movieData,
        });
    
      return self;
    }
    
    module.exports = Tabs;
    
    //then call it like:
    Tabs(window, movieData);