-
22 Nov 2011 5:47 PM #1
how to call same a function from several button tab event?
how to call same a function from several button tab event?
there are several buttons in a view, i want to do same thing when i tab these buttons, so i want to invoke a function to finish this task.
xtype:'button',
name: 'delbtn',
text:'DEL',
handler: function() {
limit = 'ok' + this.getText();
Test(limit);
}
limit: ''
Test: function(mi){
Ext.Msg.alert('me', mi);
}
i get the exception: Uncaught ReferenceError: Test is not defined
how to call same function from several button click event?
-
23 Nov 2011 9:45 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,128
- Vote Rating
- 453
MVC would be perfect for this!
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
13 Dec 2011 7:50 AM #3
Why should be used MVC to just to do that?
I have a button and I have attached a handler to it: handler: buttonPressed
var buttonPressed = function(){
}
Now the question is how to send some parameters to this function? Or how the function knows which button initiated it?
-
13 Dec 2011 9:47 AM #4
MVC is perfect because you can use ComponentQuery to add a listener to many components, using a simple selector.
As for your problem; your first post just will not work. You are defining your function inside the configuration block, which just isn't how javascript works. You need to define it outside that block, or extend the class and define it in there.
Code:var foo = function(a, b) { console.log(a, b); }; Ext.Viewport.add({ xtype: 'container', items: [ { xtype: 'button', handler: foo } ] });Code:Ext.define('MyButton', { extend: 'Ext.Button', config: { text: 'Tap me!' }, initialize: function() { this.callParent(); this.on({ scope: this, tap: function() { this.foo('a', 'b'); } }); }, foo: function(a, b) { console.log(a, b); } }); Ext.Viewport.add(Ext.create('MyButton'));Sencha Inc.
Robert Dougan - @rdougan
Sencha Touch 2 and Ext JS 4 Core Team Member, SASS/Theming Wizard.
-
13 Dec 2011 10:00 AM #5
I just can't get it...
For example I tried your first code. I made a handler that points to a function created outside the block. The function fires (the function fired also inside the block), but how can I pass some parameters to it? Where I send these 'a' and 'b'?
-
13 Dec 2011 10:20 AM #6
Here is a very simple example:
Code:Ext.setup({ onReady: function() { var foo = function(a) { console.log(a); }; Ext.Viewport.add({ xtype:'button', text: 'Hello', handler: function() { foo(this.getText()); } }); } });Sencha Inc.
Robert Dougan - @rdougan
Sencha Touch 2 and Ext JS 4 Core Team Member, SASS/Theming Wizard.


Reply With Quote