PDA

View Full Version : Question on parameters in Car Master Details demo



elgs
10 Oct 2010, 7:17 PM
CarMasterDetail = Ext.extend( CarMasterDetailUi, {
initComponent: function(){
CarMasterDetail.superclass.initComponent.call(this);
var sm = this.grid.getSelectionModel();
sm.on('rowselect', this.onGridRowSelect, this);
},
onGridRowSelect: function(sm, rowIdx, r){
this.detail.update(r.data);
}
});

Above is the code I typed in from the car demo from the extjs official website. I'm sorry if I would have any typo. I'm very confused about the onGridRowSelect function, the function signature declared 3 arguments, but I don't see how the function call passes any parameter in?

As another general question, in this case, how do I pass parameter in the function?

Thanks,
Elgs

elgs
11 Oct 2010, 8:11 AM
Can someone help me? I have been struggling on this question for a long time. I'm sorry I'm very new to OO javascript. Any help would be greatly appreciated!

Thanks,
Elgs

jarrednicholls
12 Oct 2010, 9:53 AM
Hi Elgs,

This code is subscribing an event handler named "onGridRowSelect" to the event "rowselect" of the grid's selection model:



sm.on('rowselect', this.onGridRowSelect, this);


The grid's RowSelectionModel class is what is firing this event...when it fires the event, it is passing in three arguments to the event handler(s). That is all that is happening. Does this make sense?

elgs
12 Oct 2010, 11:09 AM
Hi Jarred,

Thanks! That makes sense to me! Now I see the key point here is that the invoking of the function on is not invoking the function of onGridRowSelect, but subscribing an event handler for it.

Thanks,
Elgs