PDA

View Full Version : Button handler function in element definition



haloween
13 Dec 2011, 12:39 AM
Ext.define('ListaFilmow',{
extend: 'Ext.grid.Panel'
,alias : 'widget.listaFilmow'
,store : filmyStore
,selType: 'rowmodel'
,columns: [
{ header: 'Plik', dataIndex: 'plik',flex: 1}
,{ header: 'Nazwa Filmu', dataIndex: 'nazwa',flex: 1}
]
,tbar: [
{text: 'Dodaj',handler: this.addMovie,id: 'd_film',icon:'img/ico/add.png'}
,{text: 'UsuĊ„',id: 'u_film',icon:'img/ico/delete.png'}
]
,addMovie: function(){
alert('click');
this.store.add({nazwa: 'Kliknij i edytuj',plik:''});
}
,delMovie: function(){

}
});


addMovie doesn't get launched ... it used to work in previous versions.
I don't want to add controller and stuff since that's plain simple app not a corporate behemoth.
Any ideas ?

mankz
13 Dec 2011, 2:40 AM
You need to stop for a second and think about what 'this' means in these places of your class. For example, set a debugger after your class definition and see what 'this' points to and try to see if it makes sense.

tobiu
13 Dec 2011, 3:10 AM
mats already pointed it out.

i recommend to only add primitives directly and all other confings (objects, arrays, etc.) inside the initComponent method. inside the method this is pointing to the instance of the class.

haloween
13 Dec 2011, 3:32 AM
You need to stop for a second and think about what 'this' means in these places of your class. For example, set a debugger after your class definition and see what 'this' points to and try to see if it makes sense.

I'm aware of scope. But the problem is that it was easier to make a component bound with logic in 3.* than in 4 ....
So is there any method of adding a handletr to button in element definition or do i need to play with items and other stuff :/

haloween
13 Dec 2011, 9:33 AM
Maybe in other words:

In Ext3* when i've added a button to toolbar, and i used Ext.extend i was easily able to setup handling function in a component and map it via handler.

example:


BLAH = Ext.extend(Ext.grid.EditorGridPanel,{
initComponent:function() {
Ext.apply(this, {
tbar:[{text:'BLAH',cls:"x-btn-text-icon",icon:'blah.png',handler: this.handlerFunction,scope: this},
]
});
BLAH .superclass.initComponent.apply(this, arguments);
},
handlerFunction: function(firma_id)
{
alert('boing');
}
});

Ext.reg('blah', BLAH);


How may i do the same thing in Ext4 ?

I want to have the component logic bound to component .... That's normal.
If i have a gridpanel i'd like to have it's actions like add/delete/something in that panel.

Why am i supposed to setup controller which is totally not needed and makes stuff messy ?!

tobiu
13 Dec 2011, 9:42 AM
no one mentioned the word "controller" here, which is optional to use in 4.
if you prefer to, you can continue the ext 3 way.

did you read my answer as well?

scope, initComponent,...?

haloween
13 Dec 2011, 9:45 AM
no one mentioned the word "controller" here, which is optional to use in 4.
if you prefer to, you can continue the ext 3 way.

did you read my answer as well?

scope, initComponent,...?

Actually i looked @ the code i've posted and i'm definetly having a bad day today :)

mankz
13 Dec 2011, 9:50 AM
We all have those days :)