Search code examples
extjssencha-touchsencha-touch-2sencha-architectsencha-touch-2.1

Tap on list item works only one time


I have main page with menu. In menu I can choose section "Players", where I can see a list of all team players, tap on each player and see more detailed information. All is working fine, till I return back to main page and again to "Players" section, then tap on player doesn't works anymore, even console doesn't show any error.

I have been trying to resolve this problem for too long time, therefore I need Your help.

"Players" or users controller code:

Ext.define('HockeyTeamManagementSystem.controller.Users', {
extend: 'Ext.app.Controller',

config: {
    refs: {
        Users: 'users',
        UserInformationTab: '#UserInformationTab',
        AddUserButton: '#AddUser',
        BackToMenuButton: '#BackToMenu'
    },

    control: {
        "userlist": {
            itemtap: 'onListItemTap'
        },
        "Users": {
            backButtonCommand: 'backButtonCommand',
            BackToMenuCommand: 'backToMenuCommand'
        }
    }
},

onListItemTap: function(dataview, index, target, record, e, eOpts) {
    var user = Ext.create("HockeyTeamManagementSystem.view.UserDetailTabs", {
        title: record.data.name +" "+ record.data.lastname,
        record: record
    });
    this.getUsers().push(user);
    this.getUserInformationTab().setData(record.data);
    this.getAddUserButton().hide();
    this.getBackToMenuButton().hide();
},

backButtonCommand: function() {
    this.getAddUserButton().show();
    this.getBackToMenuButton().show();
},

backToMenuCommand: function() {
    var Dashboard = Ext.create('HockeyTeamManagementSystem.view.Dashboard');
    Ext.Viewport.setActiveItem(Dashboard);
}
});

Solution

  • Looking at the code seems like ,

    every time when you tap on list new instance gets created ,So the point is itemtap is only attached with very first instance of view to know more about this see Component life cycle.

    use Ext.ComponentQuery.query() selector to check how many instance of view has been created or just check in developer tool of the browser.

    if you want to create a view every time you should destroy it first then create.

    it should solve the problem

    Always have good practice to add view to the respective controller rather then adding at the application level ,it should reduce the loading time of application.