Sencha Touch 2 Listen Button

I have a button in the Sencha Touch 2 project. The button will be destroyed with the view after clicking and will be restored after clicking another button.

But the button does not get the listener again.

the listener builds in the view controller.

Ext.application({ name: 'App', controllers: ['Main','Home'], views: ['Main','Home'], launch: function () {Ext.Viewport.add({xtype:'mainview'});} }); 

controller

 Ext.define('App.controller.Home', {extend: 'Ext.app.Controller', config: { refs: {homeView: '#homeview',backBtn: '#btn_test1'}, control: { backBtn: { tap: function(backBtn){ console.log('[Controller][Home] btn monatsrate - - tap'); Ext.Viewport.add({xtype: 'mainview'}); Ext.Viewport.setActiveItem(1); } }, homeView: { deactivate: function (homeView){ console.log('[Controller][Home] autodestroy homeview'); //homeView.destroy(); Ext.Viewport.remove(homeView); } } } }, }); 

And submission

 Ext.define("App.view.Main", { extend:"Ext.Container", xtype:"mainview", config:{ id:'mainview', items:[ { xtype:'button', id:'btn_test2', text: 'test2' } ] }, 

});

Any idea how to allow the button to return the listener?

+4
source share
3 answers

This is because the "ref" in your controller uses the button identifier to create the link. Instead, use a different selection button for your button. For example, you can assign the property "name" to your button and assign it the value "testbutton". Then your ref will look like

 refs: {homeView: '#homeview',backBtn: 'button[name=testbutton]'}, 

I struggled with the same problem for buttons and list items that were created / destroyed many times during the application flow. Since then I have read several times that, in general, the Sencha Touch team recommends not using the identifier as a selector unless you have a specific reason. The "name" method above works very well for me. You can also use many other css-style selectors (you will need to read this separately).

As mentioned in a previous comment, I would accept some answers in order to increase the likelihood of receiving an answer to your questions in the future. I just answer this question because I hit my head against the wall on this issue for 4 hours.

+3
source

Sencha examples recommend using a button action configuration, such as "cancel", "goHome", "createPost", etc., which makes sense.
All links will then be in the form: buttons myContainer [action = myAction]

+1
source

I believe that your problem is precisely the id parameter. If you have ever added any identifier, you must make sure that it is unique, so adding id to the configuration of your user view will not create more than one instance of it! I cannot be 100% right (maybe inside the container, but I believe that this will cause problems anyway), but why do you want the identifier to be like that? Alternatively, you can simply reference your view by xtype:

 refs: {homeView: 'homeview',backBtn: 'btn_test1'}, 

Respectfully,

0
source

Source: https://habr.com/ru/post/1403219/


All Articles