Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

How to make different instances of same controller

$
0
0

I have a multi tab program that uses the same database model table to display different information on different tabs. For example i have a table that holds meeting information with rooms. Tab 1 should display information for Room A, but Tab 2 should display information for Room B. But both tabs show the same information because i am using a universal controller to bind the database information to the tableview. Is there a way to create separate instances of the controller?

Code to open the controller for Tab 1:

var cont = Alloy.createController('SessionByDay');
    cont.initWin("Grand Ballroom B");
    Alloy.CFG.nav.activeTab.open(cont.getView(), {animated:true});
Code to open the controller for Tab 2:
var cont = Alloy.createController('SessionByDay');
    cont.initWin("Grand Ballroom C");
    Alloy.CFG.nav.activeTab.open(cont.getView(), {animated:true});
Controller XML:
<Alloy>
    <Collection src="sessions" />
    <Window id="win">
        <TableView id="tblSessions" dataCollection="sessions">
            <TableViewRow id="lstRow" rowId="{id}">
                <View class="tableViewRowContainer">
                    <Label id="lblRoom" class="clsRoom" text="{room}" />
                </View>
            </TableViewRow>
        </TableView>
    </Window>
</Alloy>
Controller JS:
exports.initWin = function(_args){
    Alloy.Collections.sessions.fetch({query:"SELECT * FROM sessions WHERE room = '"+_args+"'"});
};

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>