-
16 Aug 2011 4:21 AM #1
bind a clas to a function
bind a clas to a function
Hello !
Can i bind a class to a function like JQuery ?
Your sincerlyCode:$(".mole").bind('click',function(e){ ... });
Stephan
-
16 Aug 2011 5:37 AM #2
As I don't know jQuery I'm going to make an educated guess what that code does, please correct me if I am wrong: it selects all elements with the css class 'mole' and then attaches the specified function as an event listener to all of those elements for the 'click' event.
Maybe you can do something similar in Ext with DomQuery. However, when I'm using Ext I'm rarely selecting and manipulating html elements (or indeed their Ext wrapper Ext.Element) directly. Instead I operate at the Ext.Component level, for which observeClass does a similar thing:
This adds a click event listener to all instances of Acme.widget.Code:Ext.util.Observable.observeClass(Acme.widget); Acme.widget.on('click', function() { ... });
-
16 Aug 2011 6:56 AM #3
bind event to css class
bind event to css class
Hello !
Thanks for the quick answer.
In the moment i test Ext.DomQuery and the Ext.util.Observable.
Here is my first test.
But the test don't work.
Have you an idea ?Code:var test = Array(); test = Ext.DomQuery.select('div[class=mole]'); Ext.util.Observable.observeClass(test); test.on('click',function(){ alert('click'); })
Greetings
Stephan
-
16 Aug 2011 7:41 AM #4
You can't do this, observeClass should take a class (constructor function) as a parameter, but you are passing it an array! There are 2 separate approaches, if you want to use elements, use DomQuery to grab them, then iterate them and add your event listener. If you want to use components, use observeClass.Code:Ext.util.Observable.observeClass(test);
As an aside 'var test = Array();' is pointless (and I always use the array literal [] anyway), just do 'var test = Ext.DomQuery...'


Reply With Quote