button tap not reacting when view gets added a 2nd time

痴心易碎 提交于 2019-12-01 20:26:24

问题


When an item from a list gets selected i execute the following lines of code.

this.details = Ext.create('EventManager.view.EventInfoView');
this.getNavigationView().push(this.details);

so i create a new view, and push it on a navigationview. In my controller i listen for a tap on an acceptEventButton which is inside newly created view.

Ext.define('EventManager.controller.eventController', {
extend: 'Ext.app.Controller',
config: {
    refs: {
        acceptEventButton: '#acceptEventButton'
    },

    control: {
        "acceptEventButton": {
            tap: 'onAcceptButtonTap'
        }
    }
},
...

The first time this view gets placed on the navigationview, the button tap works. When i hit the back button and push another view the button does nothing.

I'd like to solve this by doing the logic as it is now. I'd rather not add the eventlisteners myself while i'm creating the view and then push it.

Any ideas where this problem resides and how to fix?


回答1:


A new version of sencha architect was released which allows adding not listed properties.

I solved this by adding an action field on my button, and in my controller reacting to that action.

{
    xtype: 'button',
    id: 'acceptEventButton',
    ui: 'confirm',
    text: 'Accept',
    action: 'acceptEvent'
}

and in my controller i have the following lines of code

    control: {
        "button[action=acceptEvent]": {
            tap: 'onAcceptButtonTap'
        }
    }



回答2:


i faced same problem earlier and it was solved by setting
autoDestroy: false,
at config of my navigationView

its very well working after applying false to this autoDestroy property.
hope it will work for you too.




回答3:


You should change your query as follows:

control: {
    "button[id='acceptEventButton']": {
        tap: 'onAcceptButtonTap'
    }
}

As an extra information: You can also use xtype in these queries.
For example if you have a navigationview as follows:

Ext.define('app.view.Pages', {
    extend: 'Ext.NavigationView',
    xtype: 'pages',
    ...
}

and you push a list to it like this:

Ext.define('app.view.ItemList', {
    extend: 'Ext.dataview.List',
    xtype: 'itemlist',
    ...
}

then you can write your query as follows:

control: {
    "pages itemlist": {
        itemtap: 'onItemTap'
    }
}


来源:https://stackoverflow.com/questions/10208627/button-tap-not-reacting-when-view-gets-added-a-2nd-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!